Skip to content

Instantly share code, notes, and snippets.

@omerkaya1
Created November 28, 2022 19:14
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 omerkaya1/ca2adfff77dfea665dcdd1d3acbfd01b to your computer and use it in GitHub Desktop.
Save omerkaya1/ca2adfff77dfea665dcdd1d3acbfd01b to your computer and use it in GitHub Desktop.
WITH ranked_records AS (
SELECT row_number() OVER (PARTITION BY user_id, user_id ORDER BY created_at DESC) AS rn,
id, some_other_column, created_at
FROM user_status WHERE user_id IN (?)
)
SELECT
id, some_other_column, created_at
FROM ranked_records
WHERE rn=1
ORDER BY user_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment