Skip to content

Instantly share code, notes, and snippets.

@wunki
Created June 5, 2014 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wunki/b9d3e50a9adc7f6cdde6 to your computer and use it in GitHub Desktop.
Save wunki/b9d3e50a9adc7f6cdde6 to your computer and use it in GitHub Desktop.
-- name: fetch-students-for-user
-- Returns all the students for this user
SELECT *
FROM users
WHERE id IN
(SELECT user_id FROM students WHERE flow_id IN
(SELECT id FROM flows WHERE owner_id = :user_id))
@pinda
Copy link

pinda commented Jun 5, 2014

Wat vind je van deze:

SELECT *
FROM users
WHERE id IN
(SELECT DISTINCT user_id FROM students
LEFT JOIN flows ON flows.id = flow_id
WHERE owner_id = :user_id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment