SELECT e.department_id, e.first_name, d.department_name
FROM employees e
INNERJOIN departments d
-- JOIN departments dON e.department_id = d.department_id;
左外联查询
SELECT e.department_id, e.first_name, d.department_name
FROM employees e
-- LEFT JOIN departments dLEFTOUTERJOIN departments d
ON e.department_id = d.department_id;`
右外联查询
SELECT e.department_id, e.first_name, d.department_name
FROM employees e
RIGHTJOIN departments d
-- RIGHT OUTER JOIN departments dON e.department_id = d.department_id;
全外联查询
SELECT e.department_id, e.first_name, d.department_name
FROM employees e
-- FULL JOIN departments dFULLOUTERJOIN departments d
ON e.department_id = d.department_id;
额外条件过滤
SELECT e.department_id, e.first_name, d.department_name
FROM employees e
LEFTJOIN departments d
-- ON e.department_id = d.department_id AND d.department_name = 'IT'; --仍旧返回左连接结果从,不满足字段为nullON e.department_id = d.department_id
WHERE d.department_name ='IT';
SELECT*FROM employees e
JOIN departments d
--ON d.department_id = e.department_id;USING(department_id);--两张表都有同一个字段department_id
SELECT*FROM employees e
NATURALJOIN departments d;--多字段相同
自连接查询
--自引用该表的manager_id的字段填写的是employee_id的字段SELECT e.first_name, e.last_name, m.first_name, m.last_name
FROM employees e
LEFTJOIN employees m
ON e.manager_id = m.employee_id;
多表连接查询
SELECT e.first_name, e.last_name, d.department_name, j.job_title
FROM employees e
JOIN departments d
ON e.manager_id = d.department_id
JOIN jobs j
ON e.job_id = j.job_id;
1——ball——[bɔːl]——n.球——ball——ba爸(拼音)ll筷子(象形)——爸爸用筷子夹球——The kid is playing the ball. ——孩子在玩皮球。 2——boat——[bəʊt]——n.船——boat——bo60(象形)at在(熟词)——60个人在船上——I have 60 boats.——我有60艘船。 3——bag—…