Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Como encontrar LEFT OUTER JOIN ou RIGHT OUTER JOIN com ORACLE JOIN (+)


Esclareça como encontrar a junção externa direita e esquerda corretamente com um exemplo

Vou tentar mostrar a diferença entre a sintaxe de junção externa do Oracle e a Sintaxe ANSI/ISO .

LEFT OUTER JOIN -
SELECT e.last_name,
  d.department_name
FROM employees e,
  departments d
WHERE e.department_id = d.department_id(+);

SELECT e.last_name,
  d.department_name
FROM employees e
LEFT OUTER JOIN departments d
ON (e.department_id = d.department_id);

RIGHT OUTER JOIN -
SELECT e.last_name,
  d.department_name
FROM employees e,
  departments d
WHERE e.department_id(+) = d.department_id;

SELECT e.last_name,
  d.department_name
FROM employees e
RIGHT OUTER JOIN departments d
ON (e.department_id = d.department_id);

JUNÇÃO EXTERNA COMPLETA -

Antes do suporte nativo de hash full outerjoin em 11gR1, o Oracle converteria internamente o FULL OUTER JOIN da seguinte maneira -
SELECT e.last_name,
  d.department_name
FROM employees e,
  departments d
WHERE e.department_id = d.department_id(+)
UNION ALL
SELECT NULL,
  d.department_name
FROM departments d
WHERE NOT EXISTS
  (SELECT 1 FROM employees e WHERE e.department_id = d.department_id
  );

SELECT e.last_name,
  d.department_name
FROM employees e
FULL OUTER JOIN departments d
ON (e.department_id = d.department_id);

Veja isso.