Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Retreive the last ID from the details
Tue, Feb 17 2015 2:49 PMPermanent Link

Beni

Hello,

Need some help with a query, procedure, view (would prefer), whatever solution:
I have a master table ToDoList
ID (PK)
Description
and detail table ToDoListHistory
ID (PK)
ToDoListID (FK - link to ToDoList.ID)
EntryDate

I would like to get a list of ToDoList items with the latest entry from the ToDoListHistory table:
ToDoList:
1, First to do
2, Second to do
ToDoListHistory:
1, 1, 2015-02-01
2, 1, 2015-02-05
3, 2, 2015-01-01
4, 2, 2015-02-12

... and I would like to get the following result:
ToDoList.ID, ToDoList.Description, ToDoListHistory.ID, ToDoListHistory.EntryDate
1, First to do, 2, 2015-02-05
2, Second to do, 4, 2015-02-12
Tue, Feb 17 2015 11:27 PMPermanent Link

Richard Harding

Wise Nutrition Coaching

Hi Beni

How about?

SELECT
   ToDoList.ID,
   ToDoList.Description,
   T1.ToDoListId,
   T1.MaxDate
 FROM
   ToDoList
     INNER JOIN (SELECT ToDoListID, MAX(EntryDate) AS MaxDate
          FROM ToDOListHistory  GROUP BY ToDoListID) T1
       ON T1.ToDoListID = ToDoList.ID

Richard
Wed, Feb 18 2015 1:14 PMPermanent Link

Beni

Yep! It does look like a solution!

Thanks!
Image