Ver Mensaje Individual
  #5 (permalink)  
Antiguo 17/02/2014, 11:46
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, 9 meses
Puntos: 774
Respuesta: Imposible relacionar 2 veces con la misma tabla!!

entonces revisa tus datos con el ejemplo que pones y algunos datos se obtiene lo siguiente:

Código SQL:
Ver original
  1. CREATE TABLE #temp
  2. (
  3. id INT IDENTITY(1,1),
  4. titulo VARCHAR(20),
  5. idarchivo INT,
  6. idarchivo2 INT
  7. )
  8.  
  9. CREATE TABLE #temp2
  10. (
  11. id INT IDENTITY(1,1),
  12. nombre VARCHAR(20),
  13. tipo VARCHAR(20)
  14. )
  15.  
  16. INSERT INTO #temp VALUES ('Mio',1,2)
  17. INSERT INTO #temp VALUES ('Mio',3,4)
  18.  
  19. INSERT INTO #temp2 VALUES ('Test1','Testing')
  20. INSERT INTO #temp2 VALUES ('Test2','Testing')
  21. INSERT INTO #temp2 VALUES ('Test3','Testing')
  22. INSERT INTO #temp2 VALUES ('Test4','Testing')
  23.  
  24.  
  25. SELECT t1.id,t1.titulo,t2.nombre,t3.nombre FROM #temp AS t1
  26. LEFT JOIN #temp2 AS t2 ON (t1.idarchivo=t2.id)
  27. LEFT JOIN #temp2 AS t3 ON (t1.idarchivo2=t3.id)

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