Select the first instance of a record
It sounds like you're looking for DISTINCT
:
SELECT DISTINCT patientID FROM myTable
you can get the same "effect" with GROUP BY
:
SELECT patientID FROM myTable GROUP BY patientID
You could use a CTE
with ROW_NUMBER
function:
WITH CTE AS(
SELECT myTable.*
, RN = ROW_NUMBER()OVER(PARTITION BY patientID ORDER BY ID)
FROM myTable
)
SELECT * FROM CTE
WHERE RN = 1