(MAX) Group By query

jsdba

Registered User.
Local time
Today, 18:29
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.
 
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.
 
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
 
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

Back
Top Bottom