All pastes #86789 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-07-13 06:55 UTC
rendered paste body
mysql> select * from foo;
+----+-------+------+---------------------+
| id | catid | name | ts                  |
+----+-------+------+---------------------+
|  1 |     1 | cat1 | 2006-07-06 08:51:29 |
|  2 |     1 | cat1 | 2006-07-07 08:51:42 |
|  3 |     1 | cat1 | 2006-07-08 08:51:44 |
|  4 |     1 | cat1 | 2006-07-09 08:51:52 |
|  5 |     1 | cat1 | 2006-07-10 08:52:07 |
|  6 |     1 | cat1 | 2006-07-11 08:52:13 |
|  7 |     1 | cat1 | 2006-07-12 08:52:16 |
|  8 |     2 | cat2 | 2006-07-06 08:53:10 |
|  9 |     2 | cat2 | 2006-07-07 08:53:10 |
| 10 |     2 | cat2 | 2006-07-08 08:53:10 |
+----+-------+------+---------------------+
10 rows in set (0.00 sec)

mysql> select max(ts), name, id from foo group by name order by max(ts) desc;
+---------------------+------+----+
| max(ts)             | name | id |
+---------------------+------+----+
| 2006-07-12 08:52:16 | cat1 |  1 |
| 2006-07-08 08:53:10 | cat2 |  8 |
+---------------------+------+----+
2 rows in set (0.01 sec)