Ver Mensaje Individual
  #11 (permalink)  
Antiguo 15/02/2013, 11:34
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: Cantidad de registros

Código SQL:
Ver original
  1. CREATE TABLE #temp2
  2. (
  3. id INT,
  4. value1 VARCHAR(20),
  5. value2 VARCHAR(20)
  6. )
  7.  
  8. INSERT INTO #temp VALUES (1)
  9. INSERT INTO #temp VALUES (2)
  10.  
  11. INSERT INTO #temp2 VALUES (1,'1','2')
  12. INSERT INTO #temp2 VALUES (1,'2','1')
  13. INSERT INTO #temp2 VALUES (1,'3','1')
  14. INSERT INTO #temp2 VALUES (2,'1','2')
  15. INSERT INTO #temp2 VALUES (2,'2','3')
  16. INSERT INTO #temp2 VALUES (2,'3','4')
  17.  
  18.  
  19. SELECT t1.id,t2.value1,t2.value2 FROM #temp AS t1 LEFT JOIN (
  20. SELECT value1,value2,id FROM(
  21. SELECT  value1,value2,id, ROW_NUMBER() OVER(PARTITION BY id ORDER BY id) AS rn FROM #temp2 )t3 WHERE rn=1
  22. ) AS t2 ON (t1.id=t2.id)
  23. WHERE t2.id IS NOT NULL
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me