Created
June 26, 2014 15:31
-
-
Save rrreeeyyy/39b5cd0a625620f3c032 to your computer and use it in GitHub Desktop.
This file contains 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 | |
e.id AS event_id, | |
e.name, | |
s1.id AS schedule_id, | |
date_format(s1.due_date, '%Y/%m/%d') AS due_date | |
FROM events e | |
LEFT JOIN schedules s1 | |
ON e.id = s1.event_id | |
WHERE s1.id IS NULL | |
OR s1.id = ( | |
SELECT s2.id | |
FROM schedules s2 | |
WHERE s2.event_id = e.id | |
AND s2.due_date >= (SELECT max(sysdate) FROM sysdate_dummy) | |
ORDER BY | |
s2.due_date | |
LIMIT 1 | |
) | |
ORDER BY | |
s1.id IS NULL, | |
s1.due_date, | |
e.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment