Skip to content

Instantly share code, notes, and snippets.

@dahngeek
Created February 21, 2019 21:04
Show Gist options
  • Save dahngeek/9bcf8cc61a1d4d004c1c44b9de9a5b40 to your computer and use it in GitHub Desktop.
Save dahngeek/9bcf8cc61a1d4d004c1c44b9de9a5b40 to your computer and use it in GitHub Desktop.
Get the most recent row from a group by query.
SELECT `contact_id`, `user_id`, `date_backup`, `first_name`, `last_name`
FROM tbl_contacts WHERE `date_backup` IN (
SELECT MAX(`date_backup`)
FROM tbl_contacts WHERE `user_id`= 1 GROUP BY `contact_id`
)
ORDER BY `contact_id` DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment