I have the following table
recordID createdDate ForeignKeyID
00QA000000PtFXaMAN 2012-01-03 13:23:36.000 001A000000ngM21IAE
00QA000000OS2QiMAL 2011-12-15 12:03:02.000 001A000000ngM21IAE
.
.
.
.
I am trying to get the recordID for foreignKeyID where createdDAte is the min(createdDate) for foreignKeyID
if recordID is identity int I can get that by doing the following query
Select min(recordId),ForeignkeyID
from table
group by ForeignKeyId
I originaly thought that I can create temp table with the following query and then joining it to table on minDate and foreignKeyID but then I found out that there are multiple records for foreignKeyId that has the same exact createdDate.
Select min(createdDate) as minDate,ForeignKeyID
from table
group by ForeignKeyId
I'm open with using temp table or subquery or anything really. Thanks.