Skip to content

Instantly share code, notes, and snippets.

@lmatt-bit
Created March 1, 2016 06:37
Show Gist options
  • Select an option

  • Save lmatt-bit/288afceb32e97a27a250 to your computer and use it in GitHub Desktop.

Select an option

Save lmatt-bit/288afceb32e97a27a250 to your computer and use it in GitHub Desktop.
SELECT top 1 from a group (SQL Server)
SELECT a, b, c
FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY a ORDER BY b, c) rn
FROM mytable
) q
WHERE rn = 1
ORDER BY
a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment