Oracle
 sql >> Base de données >  >> RDS >> Oracle

Comment trouver LEFT OUTER JOIN ou RIGHT OUTER JOIN avec ORACLE JOIN (+)

Veuillez clarifier comment trouver correctement la jointure externe droite et gauche avec un exemple

Je vais essayer de montrer la différence entre la syntaxe de jointure externe Oracle et la syntaxe ANSI/ISO .

JOINTURE EXTERNE GAUCHE -

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);

JOINTURE EXTERNE DROITE -

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);

JOINTURE EXTERNE COMPLÈTE -

Avant la prise en charge native de la jointure externe complète de hachage dans 11gR1, Oracle convertissait en interne la FULL OUTER JOIN de la manière suivante -

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);

Regarde ça.