Skip to content

Instantly share code, notes, and snippets.

@isaacharrisholt
Created October 8, 2022 13:22
Show Gist options
  • Save isaacharrisholt/802f576c48004b22a0e801792f65f5ad to your computer and use it in GitHub Desktop.
Save isaacharrisholt/802f576c48004b22a0e801792f65f5ad to your computer and use it in GitHub Desktop.
The SQL implementation for finding users with failed orders
/* 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