Last active
September 22, 2015 05:57
-
-
Save zz/ad59b99e4a02962dd406 to your computer and use it in GitHub Desktop.
how to get max version in SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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