[MYSQL] Select Unique Where Value Is Largest

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
lenton
Forum Commoner
Posts: 49
Joined: Sun Jun 20, 2010 6:45 am

[MYSQL] Select Unique Where Value Is Largest

Post by lenton »

I have this table:
Image

I want to select all fields where time is the highest value and conversation is unique so it returns these two rows:
Image

My current SQL query doesn't give me the correct results that I'm looking for:
[text]SELECT * FROM `table` GROUP BY `conversation` ORDER BY `time` DESC[/text]
Image

I need GROUP BY to select the unique row with the highest value in `time`.
How can I achieve this?
Last edited by lenton on Sat Mar 03, 2012 8:20 am, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: [MYSQL] Select Unique Where Value Is Largest

Post by Christopher »

Try:[text]SELECT * FROM `table` GROUP BY `time`,`conversation` ORDER BY `time` DESC[/text]
(#10850)
User avatar
lenton
Forum Commoner
Posts: 49
Joined: Sun Jun 20, 2010 6:45 am

Re: [MYSQL] Select Unique Where Value Is Largest

Post by lenton »

Christopher wrote:Try:[text]SELECT * FROM `table` GROUP BY `time`,`conversation` ORDER BY `time` DESC[/text]
It returns all rows:
Image

:(
Post Reply