Created
October 8, 2022 13:22
-
-
Save isaacharrisholt/802f576c48004b22a0e801792f65f5ad to your computer and use it in GitHub Desktop.
The SQL implementation for finding users with failed orders
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
/* Naive Python implementation */ | |
SELECT * | |
FROM orders | |
WHERE NOT payment_status | |
-- Loop over the results from previous query | |
-- and run this select each time | |
SELECT * | |
FROM users | |
WHERE id = '{{ user_id }}' | |
/* SQL implementation */ | |
SELECT DISTINCT users.* | |
FROM users | |
INNER JOIN orders | |
ON users.id = orders.user_id | |
WHERE NOT orders.payment_status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment