Andy Brownsword can’t stop at one:
Having
TOP (1)return multiple rows feels wrong… but that’s whatWITH TIEScan do.For a long time I used patterns like this to get the first record in a group:
Andy goes on to explain how WITH TIES works in T-SQL, shows an alternative to using a common table expression + window function to narrow down to the first logical group, and digs into when you might not want to use that alternative.