Si es SQL tu manejador de base de datos prueba este query:
Código SQL:
Ver originalSELECT * FROM (
SELECT
ROW_NUMBER () OVER ( PARTITION BY t1.no_guia,t1.carclave ORDER BY t1.no_guia,t1.carclave ASC) AS RN,
t1.no_guia,t1.carclave,t2.fec_reg,t2.destciur FROM (
SELECT MAX(noguia) no_guia,carclave
FROM #temp
GROUP BY carclave) t1 INNER JOIN (
SELECT carclave,fec_reg,destciur FROM #temp
) t2 ON (t1.carclave=t2.carclave)
)t3 WHERE rn=1
regresa:
RN no_guia carclave fec_reg destciur
1 00000134 c-223 2011-02-12 00:00:00.000 cancun
1 00000234 c-45 2011-02-16 00:00:00.000 tultitlan
Saludos!