Last active
August 29, 2015 13:57
-
-
Save ypercube/9758793 to your computer and use it in GitHub Desktop.
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
SELECT task_events.task_id, task_events.state | |
FROM tasks | |
INNER JOIN task_events ON task_events.task_id = tasks.id | |
WHERE task_events.created_at = | |
(SELECT MAX(task_events.created_at) FROM task_events WHERE task_events.task_id = tasks.id) | |
GROUP BY tasks.id, task_events.id | |
ORDER by tasks.id ; | |
SELECT DISTINCT ON (task_id) | |
task_id, state | |
FROM task_events | |
ORDER by task_id, created_at DESC ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment