MySQL SQL Query Help

From: Date: Mon, 13 Nov 2006 22:58:30 +0000
Subject: MySQL SQL Query Help
Groups: php.db 
Request: Send a blank email to php-db+get-42666@lists.php.net to get a copy of this message
I have a table:
id fkid   foo    bar
1  1      345    yellow
2  1      34     red
3  2      3459   green
4  2      345    brown
I want to select the largest value of "foo" for a unique fkid, and return bar, the results ordered by bar. In this case, 345 is the largest value of foo for fkid 1, and 3459 is the largest for fkid 2. "green" comes before "yellow." My desired result set would be:
    fkid   foo    bar
    2      3459   green
    1      345    yellow
How would I write that in SQL? fkid and foo are ints, bar is a varchar. Beckman ---------------------------------------------------------------------------
Peter Beckman                                                  Internet Guy
beckman@purplecow.com                             http://www.purplecow.com/
---------------------------------------------------------------------------

« previous php.db (#42666) next »