學(xué)生表:
班級(jí)表:
1.內(nèi)連接查詢:查詢的結(jié)果為兩個(gè)表匹配到的數(shù)據(jù)
select * from students inner join classes on students.cls_id = classes.id;
2.左連接查詢:查詢的結(jié)果為兩個(gè)表匹配到的數(shù)據(jù),左表特有的數(shù)據(jù)吹泡,對(duì)于右表中不存在的數(shù)據(jù)使用null
select * from students as s left join classes as c on s.cls_id = c.id;
3.右連接查詢:查詢的結(jié)果為兩個(gè)表匹配到的數(shù)據(jù)酪术,右表特有的數(shù)據(jù)器瘪,對(duì)于左表中不存在的數(shù)據(jù)使用null
select * from students as s right join classes as c on s.cls_id = c.id;