Last active
November 15, 2022 12:39
-
-
Save mikehins/5da1dba8c42bf94c7e731d22b895e331 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
# https://sqlfordevs.com/for-each-loop-lateral-join | |
SELECT customers.*, recent_sales.* | |
FROM customers | |
LEFT JOIN LATERAL ( | |
SELECT * | |
FROM sales | |
WHERE sales.customer_id = customers.customer_id | |
ORDER BY created_at DESC | |
LIMIT 3 | |
) AS recent_sales ON true; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment