Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/12/2014, 08:42
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: Duda con consulta

sencillo con un left/right join a la misma tabla usando un alias para cada una de las tablas.........


Código SQL:
Ver original
  1. CREATE TABLE #temp(
  2. id INT,
  3. empleados VARCHAR(20),
  4. idsupervisor INT
  5. )
  6.  
  7. INSERT INTO #temp  VALUES (12,'danilo',NULL )
  8. INSERT INTO #temp  VALUES (15,'michael',NULL )
  9. INSERT INTO #temp  VALUES (16,'frank',12 )
  10. INSERT INTO #temp  VALUES (18,'mayra',15)
  11.  
  12.  
  13.  
  14. SELECT t2.id,t2.empleados,t1.id,t1.empleados FROM #temp AS t1
  15. LEFT JOIN #temp AS t2 ON (t1.id=t2.idsupervisor)
  16. 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