Skip to content

Instantly share code, notes, and snippets.

@zz
Last active September 22, 2015 05:57
Show Gist options
  • Save zz/ad59b99e4a02962dd406 to your computer and use it in GitHub Desktop.
Save zz/ad59b99e4a02962dd406 to your computer and use it in GitHub Desktop.
how to get max version in SQL
/**
MariaDB [temp]> select * from file;
+------+---------+
| id | version |
+------+---------+
| 1 | 10 |
| 1 | 11 |
| 1 | 12 |
| 2 | 10 |
| 2 | 11 |
+------+---------+
**/
MariaDB [temp]> select id as id, version from file as f \
where version = ( select version from file where id=f.id order by version desc limit 1 );
+------+---------+
| id | version |
+------+---------+
| 1 | 12 |
| 2 | 11 |
+------+---------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment