Created
April 5, 2017 22:43
-
-
Save jylopez/be2c31e793bad6a636ac6d3a2bc90b24 to your computer and use it in GitHub Desktop.
Postgres example distinct
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
WITH cohorts_join AS (SELECT | |
cohorts.id, | |
cohorts.name, | |
cohorts.settings, | |
cohorts.created_at, | |
cohorts.updated_at, | |
registrations.product_id, | |
products.type AS product_type | |
FROM cohorts, cohorts_registrations, registrations, products | |
WHERE | |
cohorts.id = cohorts_registrations.cohort_id | |
AND cohorts_registrations.registration_id = registrations.id | |
AND registrations.product_id = products.id | |
) | |
SELECT DISTINCT ON (id, product_id) * FROM cohorts_join; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment