Basic Join 基本交,Cross Join 叉交,INNER JOIN 內(nèi)交,OUTER JOIN 外交,Left join 左交,Right join 右交,F(xiàn)ull join全交
Basic Join Operation--comma-separated join(叉乘,都乘到N*M,N,M分別是兩個表的條數(shù))
馬克-to-win: select * from register, student;
馬克- to-win:馬克 java社區(qū):防盜版實名手機尾號: 73203。
Cross Join(叉乘,都乘到N*M,N,M分別是兩個表的條數(shù))---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
交叉聯(lián)接的作用同內(nèi)聯(lián)接一樣。例如,下面的 Transact-SQL 查詢得到相同的結(jié)果集:
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補上,見目錄里的例子。