In my SQL query I'm trying to get data from database that has the newest combination of Date and Time for each Project No.
My formula is:
select [Project], [Machine], [Category], [Details], MAX(date + ' ' + time) as [DateTime]
from [SQL].[dbo].[ZMAC] group by [Project No], [Machine], [Repair Category], [Details]
Here is a part of the search result
| Project | Machine | Category | Details | DateTime |
------------------------------------------------------------------------
| M00004 | A09 | QC | CENTER OVER | 2020-01-21 19:15:00.000 |
| M00004 | A09 | QC | FIRST CUT | 2020-01-21 19:00:00.000 |
| M00006 | C03 | QC | PUSHER UP | 2020-01-21 17:30:00.000 |
The query ends up giving me 2 rows of M00004
because Details is different. What I really wanted is for the table to return me 1 row for each Project.
| Project | Machine | Category | Details | DateTime |
------------------------------------------------------------------------
| M00004 | A09 | QC | CENTER OVER | 2020-01-21 19:15:00.000 |
| M00006 | C03 | QC | PUSHER UP | 2020-01-21 17:30:00.000 |
How do I tell the formula to only show me the latest entry only?