mysql> select catid,name,ts from foo group by name order by (select max(ts) from foo where name in (select distinct nam e from foo)); +-------+------+---------------------+ | catid | name | ts | +-------+------+---------------------+ | 1 | cat1 | 2006-07-06 08:51:29 | | 2 | cat2 | 2006-07-06 08:53:10 | +-------+------+---------------------+ 2 rows in set (0.00 sec) mysql> select distinct name from foo; +------+ | name | +------+ | cat1 | | cat2 | +------+ 2 rows in set (0.00 sec) mysql> select max(ts) from foo where name in (select distinct name from foo)); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio n for the right syntax to use near ')' at line 1 mysql> select max(ts) from foo where name in (select distinct name from foo); +---------------------+ | max(ts) | +---------------------+ | 2006-07-12 08:52:16 | +---------------------+ 1 row in set (0.00 sec) mysql> select max(ts), name, from foo group by name order by max(ts) desc; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio n for the right syntax to use near 'from foo group by name order by max(ts) desc' at line 1 mysql> select max(ts), name, from foo group by name order by max(ts); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio n for the right syntax to use near 'from foo group by name order by max(ts)' at line 1 mysql> select max(ts), name, from foo group by name; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio n for the right syntax to use near 'from foo group by name' at line 1 mysql> select max(ts), name, from foo; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio n for the right syntax to use near 'from foo' at line 1 mysql> select max(ts), name from foo group by name order by max(ts) desc; +---------------------+------+ | max(ts) | name | +---------------------+------+ | 2006-07-12 08:52:16 | cat1 | | 2006-07-08 08:53:10 | cat2 | +---------------------+------+ 2 rows in set (0.00 sec)