#交叉连接(返回笛卡尔交集)
AXB={(a,b)|a属于A且b属于B },则AXB所形成的集合就叫笛卡尔集
1 SELECT * from employees cross join depts; 2 SELECT * from employees,depts;
#内连接(只返回满足连接条件的记录,不返回不满足连接条件的记录)
1 select * from employees t1 INNER join depts t2 2 on t1.dept_id = t2.dept_id;
#右外连接(不仅返回满足连接条件的记录,不满足连接条件的记录也返回,但是不返回从表里不满足连接条件的记录)
1 select * from employees t1 RIGHT join depts t2 2 on t1.dept_id = t2.dept_id;
#左外连接(不仅返回满足连接条件的记录,不满足连接条件的记录也返回,但是不返回从表里不满足连接条件的记录)
select * from employees t1 LEFT join depts t2 on t1.dept_id = t2.dept_id;
SELECT t1.name ‘员工姓名‘, t2.name ‘所在部门‘ from employees t1
1 left join depts t2 on t1.dept_id = t2.dept_id;
原文地址:https://www.cnblogs.com/jinjiajun/p/9015771.html
时间: 2024-10-11 23:01:58