Mysql教程:(四)连接查询

连接查询

1、左连接查询:

mysql> select stu.*,sc.*,maths+sc.chinese+sc.english from student stu left join score sc on stu.id=sc.id;

注释:stu:为别名。student stu left join score:student:为主表,score为副表显示。 left join:为左连接。 两表关联:其ID必须一一对应(stu.id=sc.id);

2、右连接查询:

mysql> select stu.*,sc.*,maths+sc.chinese+sc.english from student stu right join score sc on stu.id=sc.id;

3、内连接查询:两个表同时都有的内容才会显示。

mysql> select stu.*,sc.*,maths+sc.chinese+sc.english from student stu join score sc on stu.id=sc.id;

4、显示查询数据连接:把后表与前排合起来在一个表显示。

select id,name,class from student union select class,number,maths from score;

posted on 2021-11-06 11:33  hello_殷  阅读(79)  评论(0)    收藏  举报

导航

作者:hello.殷
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文链接,否则保留追究法律责任的权利。