Skip to content

Instantly share code, notes, and snippets.

@rdapaz
Created July 24, 2024 05:53
Show Gist options
  • Save rdapaz/f2a73a9659bc82bcabcaacb5e82a170c to your computer and use it in GitHub Desktop.
Save rdapaz/f2a73a9659bc82bcabcaacb5e82a170c to your computer and use it in GitHub Desktop.
Grab latest entry from database
SELECT *
FROM Summary t1
INNER JOIN (
SELECT system_id, MAX(ID) as max_id
FROM Summary
WHERE facility = 'MAC'
GROUP BY system_id
) t2 ON t1.system_id = t2.system_id AND t1.ID = t2.max_id
WHERE t1.facility = 'MAC'
ORDER BY T1.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment