Last active
February 18, 2021 14:54
-
-
Save wujku/b1c033aeb8ddc415817d 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 c.*, p1.* | |
FROM customer c | |
JOIN purchase p1 ON (c.id = p1.customer_id) | |
LEFT OUTER JOIN purchase p2 ON (c.id = p2.customer_id AND | |
(p1.date < p2.date OR p1.date = p2.date AND p1.id < p2.id)) | |
WHERE p2.id IS NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Second example: