Last active
December 31, 2020 11:05
-
-
Save lil12t/2df9438d5b19417534b9ee144c5d14b4 to your computer and use it in GitHub Desktop.
Select latest items grouped by status (non duplicates)
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
/* OUTPUTS ALL STATUSES WITH LATEST ITEM, 4 STATUSES = 4 ITEMS IN OUTPUT */ | |
SELECT m1.* | |
FROM stats m1 | |
LEFT JOIN stats m2 | |
ON (m1.status = m2.status AND m1.created_at < m2.created_at) | |
WHERE m2.id IS NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment