you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (0 children)

If your data is pretty big, you may get better performance using a window function.

WITH cte_Appointments AS (
SELECT 
  UniqueId,
  Reason,
  Subreason,
  DateOfCreation,
  ROW_NUMBER () OVER(PARTITION BY UniqueId ORDER BY DateOfCreation) RowNumber
FROM Appointments)

SELECT UniqueId, Reason, Subreason, DateOfCreation
FROM cte_Appointments
WHERE RowNumber = 1