Ver Mensaje Individual
  #2 (permalink)  
Antiguo 05/06/2014, 16:25
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: listar solo un registro repetido

Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. rut VARCHAR(20),
  4. nombre VARCHAR(20),
  5. fecha datetime
  6. )
  7. INSERT INTO #temp VALUES ('11111111-1','juan','05-05-2014')
  8. INSERT INTO #temp VALUES ('11111111-1','juan','06-06-2014')
  9.  
  10.  
  11. SELECT t1.* FROM #temp AS t1
  12. LEFT JOIN (SELECT MAX(fecha) AS fecha,rut,nombre FROM #temp GROUP BY rut,nombre) AS t2 ON (t1.rut=t2.rut AND t1.fecha=t2.fecha)
  13. WHERE t2.fecha IS NOT NULL

saludos!
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me