I have the following data in a MySQL database table called MyTable:
+----------+------------+---------------------+
| my_id | country_gb | date_updated |
+----------+------------+---------------------+
| 10 | 224 | 2013-02-07 00:00:00 |
| 30 | 224 | 2013-02-07 00:00:00 |
| 40 | 299 | 2013-02-07 00:00:00 |
| 60 | 277 | 2013-02-09 00:00:00 |
| 70 | 222 | 2013-02-09 00:00:00 |
| 100 | 349 | 2013-02-09 00:00:00 |
How do I query the database so that only the rows with the latest date is returned?
I know I could do SELECT * from 'MyTable' WHERE 'date_updated'="2013-02-09 00:00:00", but what if I don’t now the specific date_updated (as I don’t)? I thought I could sort the table by date_updated DESC in one command (something like SELECT date_updated FROM 'MyTable' ORDER BY date_updated DESC LIMIT 1) and then use the date_updated value to do another search but I don’t know how to do this all in one command or even if there is a way.
Use subquery