Basic Join 基本交,Cross Join 叉交,INNER JOIN 内交,OUTER JOIN 外交,Left join 左交,Right join 右交,Full join全交都是什么?

it2024-12-01  3

Basic Join Operation--comma-separated join(叉乘,都乘到N*M,N,M分别是两个表的条数) 马克-to-win:  select * from register, student;

Cross Join(叉乘,都乘到N*M,N,M分别是两个表的条数)---same as comma-separated join

select * from register CROSS JOIN student;

select r.name, s.name,s.age from register r CROSS JOIN student s where r.id = s.id AND s.age >20;

INNER JOIN

交叉联接的作用同内联接一样。例如,下面的 Transact-SQL 查询得到相同的结果集: 

select * from register INNER JOIN student;

select r.name, s.name,s.age from register r INNER JOIN student s on r.id = s.id AND s.age >20;

 

OUTER JOIN Left join Return all matched rows and all unmatched rows from the left table Right join Return all matched rows and all unmatched rows from the right table Full join Return all matched and unmatched rows from both tables select * from register as r left join student as s on r.id = s.id; select * from register as r right join student as s on r.id = s.id; select * from register as r full join student as s on r.id = s.id;(mysql不支持full join)

比较:inner join,cross join,join只是找回所有符合条件的行,不基于谁,不返回null。但外交不一样, Left join时,左表全回来,右表用null补上,见目录里的例子。

 

更多请看下节:http://www.mark-to-win.com/tutorial/mydb_DBIntroduction_DifferenceInnerOuterJoin.html

最新回复(0)