Query to return max date for multiple rows

MPFraser7

New Member
Joined
Dec 14, 2016
Messages
34
Hello,

I'm trying to query a table to return records with the latest contract date. I've tried a bunch of max date codes that I found on the forum but none of them seem to return what I'm looking for. Here's my table:
GroupLevelContractDateSalary
A101/04/200110000
A101/04/200211000
A201/04/200120000
A201/04/200221000
B101/06/200110000
B101/06/200211000

<tbody>
</tbody>

I'm trying to get the following results:

GroupLevelContractDateSalary
A101/04/200211000
A201/04/200221000
B101/06/200211000

<tbody>
</tbody>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hello,

here is what I would personally do to get the result that you want.

Subquery (I name it sub1)

Select table.Group, table.Level, Max(table.ContractDate) AS LastContractDate
From table
Group by table.Group, table.Level

Create a Join to add the Salary column

Select sub1.Group, sub1.Level, sub1.LastContratDate, table.Salary
From table Join sub1 on (sub1.Group = table.Group) and (sub1.Level = table.Level)
Order by sub1.Group, sub1.Level, sub1.LastContratDate, table.Salary

Edit : The table name is an example, I highly doubt that your table name is "table"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,683
Messages
6,161,264
Members
451,692
Latest member
jmaskin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top