Skip to content
Advertisement

Query to obtain the maximum primary key ID of a table for each unique value of the customerID column in the same table

I’m trying to run a query that takes obtains the maximum QuestionnaireId value for each unique value in column VendorId.

So for example from this table:

I would obtain:

I’m using the following code to get the maximum QuestionnaireId, but need another statement alongside it to get the unique VendorIds as well. Note that the statement I’ve included is just last segment of a large Join function to combine all of my tables into one.

Advertisement

Answer

Just use aggregation:

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