L'une des façons de le faire est
select A.ForeignKeyID, R.recordID
from (select distinct t.ForeignKeyID from table as t) as A
outer apply
(
select top 1 t.recordID
from table as t where t.ForeignKeyID = A.ForeignKeyID
order by t.createdDate asc
) as R
Une autre façon de le faire est
select top 1 with ties
t.recordID, t.ForeignKeyID
from table as t
order by row_number() over (partition by t.ForeignKeyID order by t.createdDate)
Et une autre façon
select A.recordID, A.ForeignKeyID
from
(
select
t.recordID, t.ForeignKeyID,
row_number() over (partition by t.ForeignKeyID order by t.createdDate) as RowNum
from table1 as t
) as A
where A.RowNum = 1
J'aime le deuxième plus que les autres à cause de la brièveté du code