Created
December 11, 2013 09:07
-
-
Save Cezarion/7907226 to your computer and use it in GitHub Desktop.
Select all rows by max date
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
| /* -------------------------------------------------------------- | |
| DB MODEL | |
| ID Type_id Name Value Date | |
| -- -------- ------ ------- --------------------- | |
| 1 56 "name1" "lorem" "2011-03-19 22:08:13" | |
| 5 58 "name2" "ipsum" "2011-03-19 22:00:44" | |
| 22 58 "name2" "dolor" "2011-03-20 11:03:13" | |
| 31 25 "name3" "sit" "2011-04-28 18:42:07" | |
| 44 12 "name4" "amet" "2011-04-12 11:06:11" | |
| 98 45 "name5" "consectetur" "2011-03-19 22:46:04" | |
| 211 12 "name4" "adipiscing" "2011-03-19 22:25:24" | |
| 217 25 "name3" "elit" "2011-03-19 22:25:24" | |
| -------------------------------------------------------------- */ | |
| SELECT * FROM my_table | |
| INNER JOIN (SELECT Type_id, MAX(Date) as TopDate FROM my_table GROUP BY Type_id ) AS EachItem | |
| ON EachItem.TopDate = my_table.Date | |
| AND EachItem.Type_id = my_table.Type_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment