I am a SQL Novice in need of some advice. What is the most efficient (fastest running query) way to do the following-
Select all columns from a table after-
-Performing a "Group By" based on the unique values contained in two columns: "top_line_id" and "external_reference".
-Selecting a single record from each group based on the max or min value (doesn't matter which one) contained in a different field such as support_id.
Someone on my team provided the below query, but I can't seem to get it working. I receive an error message stating "invalid relational operator" when I attempt to execute it.
Select *
from STAGE.SFS_GH_R3_IB_ENTLMNT_CONTACTS
Where support_id, external_reference, top_line_id in (
select max(support_id),
external_reference,
top_line_id from STAGE.SFS_GH_R3_IB_ENTLMNT_CONTACTS
)
One more thing - the columns on which we are performing the Group By contain null values in some records. We would like those excluded from the query.
Any assistance you can provide is very much appreciated.