sql连接查询INNER JOIN,LEFT JOIN,RIGHT JOIN区别

测试表

课程表cource

sql连接查询INNER JOIN,LEFT JOIN,RIGHT JOIN区别

教师表teacher

sql连接查询INNER JOIN,LEFT JOIN,RIGHT JOIN区别

查询老师教的课程

1.inner join内链接 ,只显示完全匹配的查询结果

SELECT  cource.cname,teacher.tname from cource INNER JOIN teacher on teacher.tid=cource.tid;

sql连接查询INNER JOIN,LEFT JOIN,RIGHT JOIN区别

注意:查询结果和多表查询结果一致

select cname,tname from cource,teacher  where cource.tid=teacher.tid;

2. left join 左连接 ,返回左表所有的行,即使右表中没有匹配 的查询结果

SELECT  cource.cname,teacher.tname from cource LEFT JOIN teacher on teacher.tid=cource.tid;

sql连接查询INNER JOIN,LEFT JOIN,RIGHT JOIN区别

3. right join 右连接,返回右边的表所有的行,即使左边额没有匹配的查询结果

SELECT  cource.cname,teacher.tname from cource right JOIN teacher on teacher.tid=cource.tid;

sql连接查询INNER JOIN,LEFT JOIN,RIGHT JOIN区别

full join 我执行报错,没找到原因,如果知道的请留言给我,谢谢

SELECT  cource.cname,teacher.tname from cource full JOIN teacher on teacher.tid=cource.tid;

报错

sql连接查询INNER JOIN,LEFT JOIN,RIGHT JOIN区别

上一篇:Xcode 设置图片全屏显示


下一篇:How to create Web Deployment Package and install the package