当前位置: 代码迷 >> SQL >> SQL联接,Oracle关联加号(+)等相关知识
  详细解决方案

SQL联接,Oracle关联加号(+)等相关知识

热度:70   发布时间:2016-05-05 14:02:07.0
SQL连接,Oracle关联加号(+)等相关知识

1. LEFT OUTER JOIN:左外关联
SELECT e.last_name, e.department_id, d.department_name
FROM employees e
LEFT OUTER JOIN departments d
ON (e.department_id = d.department_id);

等价于

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


结果为:所有员工及对应部门的记录,包括没有对应部门编号department_id的员工记录。

2. RIGHT OUTER JOIN:右外关联

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

等价于

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

结果为:所有员工及对应部门的记录,包括没有任何员工的部门记录。

3. FULL OUTER JOIN:全外关联

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

结果为:所有员工及对应部门的记录,包括没有对应部门编号department_id的员工记录和没有任何员工的部门记录。

  相关解决方案