Sqlserver
 sql >> Base de données >  >> RDS >> Sqlserver

Comment sélectionner uniquement la dernière entrée dans une table ?

select p.projectName, t.ThingName
from projects p
join projectThingLink l on l.projectId = p.projectId
join thing t on t.thingId = l.thingId
where l.createdDate =
( select max(l2.createdDate)
  from projectThingLink l2
  where l2.thingId = l.thingId
);

NOTE :Corrigé après commentaire