I have this releases
table in a SQLite3 database, listing each released version of an application:
|release_id|release_date|app_id|
|==========|============|======|
| 1001| 2009-01-01 | 1|
| 1003| 2009-01-01 | 1|
| 1004| 2009-02-02 | 2|
| 1005| 2009-01-15 | 1|
So for each app_id, there will be multiple rows. I have another table, apps
:
|app_id|name |
|======|========|
| 1|Everest |
| 2|Fuji |
I want to display the name of the application and the newest release, where "newest" means (a) newest release_date, and if there are duplicates, (b) highest release_id.
I can do this for an individual application:
SELECT apps.name,releases.release_id,releases.release_date
FROM apps
INNER JOIN releases
ON apps.app_id = releases.app_id
WHERE releases.release_id = 1003
ORDER BY releases.release_date,releases.release_id
LIMIT 1
but of course that ORDER BY applies to the whole SELECT query, and if I leave out the WHERE clause, it still returns only one row.
It's a one-shot query on a small database, so slow queries, temp tables, etc. are fine - I just can't get my brain around the SQL way to do this.