Add additional "max" statement to 4-line SQL Code

jwb1012

Board Regular
Joined
Oct 17, 2016
Messages
167
Hello, I am very new to SQL and Access - most of my experience is in VBA and Excel. I am trying to add "max" to the "TXN_Number" field...Any guidance would be much appreciated.

Code:
SELECT t.ID, t.TXN_Type, t.Program_TXN_Number, t.TXN_Date
FROM PURCHASING_DB AS t INNER JOIN (SELECT ID, max(TXN_Date) AS MaxDate FROM PURCHASING_DB GROUP BY ID)  AS tm ON (t.ID= tm.ID) AND (t.TXN_Date = tm.MaxDate)
WHERE (((t.TXN_Type)="Purchase" Or (t.TXN_Type)="Initial Balance"));
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
So what do you want to see in your results? Maybe something like:
Code:
ID                     TXN_TYPE          Program_TXN_NUMBER      MaxDate
1                       Purchase            44                           12/12/2016
1                       Initial Balance    55                            10/01/2016
2                       Purchase            44                           09/07/2016
2                       Initial Balance     55                           08/31/2016

??
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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