sql >> Base de Datos >  >> RDS >> Sqlserver

seleccionando la columna 1 superior con la columna 2 coincidente

de una manera

select t1.* from
(select id,max(pid) as Maxpid
from yourtable
group by id) t2
join yourtable t1 on t2.id = t1.id
and t2.Maxpid = t1.pid