Select multiple records from sql database table in a master-detail scenario
Posted
by Trex
on Stack Overflow
See other posts from Stack Overflow
or by Trex
Published on 2010-05-29T09:48:25Z
Indexed on
2010/05/29
9:52 UTC
Read the original article
Hit count: 310
sql
|master-pages
Hello, I have two tables in a master-detail relationship. The structure is more or less as follows: Master table:
MasterID, DetailID, date, ...
masterID1, detailID1, 2010/5/1, ....
masterID2, detailID1, 2008/6/14, ...
masterID3, detailID1, 2009/5/25, ...
masterID4, detailID2, 2008/7/24, ...
masterID5, detailID2, 2010/4/1, ...
masterID6, detailID4, 2008/9/16, ...
Details table:
DetailID, ...
detailID1, ...
detailID2, ...
detailID3, ...
detailID4, ...
I need to get all the records from the details table plus the LAST record from the master table (last by the date in the master table). Like this:
detailID1, masterID1, 2010/5/1, ....
detailID2, masterID5, 2010/4/1, ...
detailID3, null, null, ...
detailID4, masterID6, 2008/9/16, ...
I have no idea how to do this. Can anybody help me? Thanks a lot. Jan
© Stack Overflow or respective owner