Skip to content

Instantly share code, notes, and snippets.

@ketanbhatt
Last active October 18, 2019 09:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ketanbhatt/9771b4caa5f9ef2fe6aaa32935e8cb17 to your computer and use it in GitHub Desktop.
Save ketanbhatt/9771b4caa5f9ef2fe6aaa32935e8cb17 to your computer and use it in GitHub Desktop.
Avoid Joins: Evaluate and Select Query
WITH user_ids AS
(SELECT id
FROM user
WHERE account_id IN
(SELECT generate_series(1,1000)))
SELECT purchase.id
FROM purchase
WHERE user_id IN
(SELECT id
FROM user_ids);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment