Selecting only the Max row through SQL

Tskutnik

Registered User.
Local time
Today, 18:23
Joined
Sep 15, 2012
Messages
234
A query TaxType_Query produces the following results

TaxType; FromDate; ContactID, FullName
W2; 7/1/15; 1, Tom
1099; 4/1/15; 1,Tom
W2; 1/1/15; 1, Tom
W2; 1/1/10; 2, Dick
1099; 1/1/09; 3, Harry

I need the query to show only the rows with the maximum FromDate for each ContactID (result would be the 1st, 4th and 5th rows only).
I assume there is a quick SQL statement that will work better than Totals / Max criteria method. If I set the FromDate criteria to Max the TaxType field is a problem as they have different values I cannot group by that field.

If someone could assist the with SQL code I’d appreciate the help.

Thanks
 
You would make a subquery. Generate the Maximum FromDate for every Contact ID. Then you build a query on top of it, using that subquery and the TaxType_Query. Link them by ContactID and their date fields and bring in all the data from TaxType_Query.
 

Users who are viewing this thread

Back
Top Bottom