Skip to content
Advertisement

Include all selected types, filter out duplicate where primaryType takes precedence

What I’m trying to accomplish is select from a table and return all the records where the Type matches one of the parameter types. Remove duplicates with the primaryType being the record of choice if found, if not then a single record from one of the other type arguments. The order doesn’t matter for the other types although it would be nice (can pick @secondType or @thirdType). This is a POC project so if I need to add or change things to make it easier/faster I’m open to ideas!

Desired result…

I’ve tried something like the code below as well as other code but just can’t seem to nail it down.

Where the code above gets hung up is the order by Type can return the wrong result because the @primaryType may be further down the list when sorted. Which would return @secondType or @thirdType depending on the sorted result.

Advertisement

Answer

You are almost there, just use the @Type values in the over(order by) clause to create custom ordering/precedence.

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