1、笛卡兒積
select * from emp,dep;
select * from emp,dep where emp.dep_id = dep.id;
select * from emp,dep where emp.dep_id = dep.id and dep.name = "技術(shù)";
2、內(nèi)連接:只取兩張表有對(duì)應(yīng)關(guān)系的記錄
select * from emp inner join dep on emp.dep_id = dep.id;
select * from emp inner join dep on emp.dep_id = dep.id
where dep.name = "技術(shù)";
inner join 連接兩個(gè)表, where過(guò)濾條件,只取條件符合的
3、左連接: 在內(nèi)連接的基礎(chǔ)上保留左表沒(méi)有對(duì)應(yīng)關(guān)系的記錄
select * from emp left join dep on emp.dep_id = dep.id;
4、右連接: 在內(nèi)連接的基礎(chǔ)上保留右表沒(méi)有對(duì)應(yīng)關(guān)系的記錄
select * from emp right join dep on emp.dep_id = dep.id;
5、全連接:在內(nèi)連接的基礎(chǔ)上保留左、右面表沒(méi)有對(duì)應(yīng)關(guān)系的的記錄
select * from emp left join dep on emp.dep_id = dep.id
union
select * from emp right join dep on emp.dep_id = dep.id;
網(wǎng)頁(yè)標(biāo)題:MYSQL的多表查詢(xún)
分享網(wǎng)址:
http://weahome.cn/article/pogjcg.html