Skip to content
Advertisement

SQL Server : need help write what i think should be a simple code

I have a simple table:

I would like to return one row for each id_fk. If the default is T then return that one. If their is no default T then return default F.

It seems simple enough but I have been struggling.

Advertisement

Answer

One option is to filter with a correlated subquery:

This produces one record for each id_fk: priority is given to the record that has 'T'as default, and then to the smalles id.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement