Hi James, all!

James Lockie wrote:
Say I have x rows of 2 columns each.
For example, 2 rows:  'A 10:00pm' and 'A 11:00pm'.

I want to return one 'A' row with the latest time (eg. 'A 11:00pm).

I could do 'select distinct(col1) from table' and then 'select
col1, max( col2 ) where col1=row[0]'?

Is there a way to do it in one select?

1) *Please*, tell us the version you are using.
   Very often, and anwer to such a question will be version-specific.

2) Read up about "group by":
   SELECT col1, max(col2) FROM tab [ WHERE .... ] GROUP BY col1
should do what you want, if I get your question right.
The WHERE clause is only needed if you do not want to get these results for all values of col1.


HTH,
Joerg

--
Joerg Bruehe, Senior Production Engineer
MySQL AB, www.mysql.com

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to