(MAX) Group By query (1 Viewer)

jsdba

Registered User.
Local time
Today, 13:37
Joined
Jun 25, 2014
Messages
165
Hi Experts

I have a table tblNote with the following fields:
  • NoteID
  • TaskID
  • ReminderDate
  • Note

I need a select query that will retrieve the record with furthest date group by TaskID. The query must include the the Note field. Heres my starting point.
Code:
SELECT TaskID, MAX(ReminderDate), Note FROM tblNote Group By TaskID

This doesn't work because i know i also need to group by Note. Can anyone point me in the right direction.
 

isladogs

MVP / VIP
Local time
Today, 18:37
Joined
Jan 14, 2017
Messages
18,216
i'm not clear what you're asking but possibly just

Code:
SELECT TaskID, Note, MAX(ReminderDate) FROM tblNote Group By TaskID, Note

If that's not right can you explain what you mean by furthest date group.
Preferably with some example data for clarity.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 10:37
Joined
Oct 29, 2018
Messages
21,469
Or how about?
Code:
SELECT T1.TaskID, T1.ReminderDate, T1.Note
FROM tblNote T1
INNER JOIN (SELECT T2.TaskID, MAX(T2.ReminderDate) As LastNoteDate
     FROM tblNote T2
     GROUP BY T2.TaskID) SQ
ON T1.TaskID=SQ.TaskID
     AND T1.RemiderDate=SQ.LastDate
 

jsdba

Registered User.
Local time
Today, 13:37
Joined
Jun 25, 2014
Messages
165
Or how about?
Code:
SELECT T1.TaskID, T1.ReminderDate, T1.Note
FROM tblNote T1
INNER JOIN (SELECT T2.TaskID, MAX(T2.ReminderDate) As LastNoteDate
     FROM tblNote T2
     GROUP BY T2.TaskID) SQ
ON T1.TaskID=SQ.TaskID
     AND T1.RemiderDate=SQ.LastDate

Worked like a charm. Thank you
 

Users who are viewing this thread

Top Bottom