当前位置:藏獒宠物网>百科>综合>正文

sql关联表查询语句

人气:217 ℃/2023-07-23 15:12:58

一、外连接

1.左连接 left join 或 left outer join

SQL语句:select * from student left join score on student.Num=score.Stu_id;

2.右连接 right join 或 right outer join

SQL语句:select * from student right join score on student.Num=score.Stu_id;

3.完全外连接 full join 或 full outer join

SQL语句:select * from student full join score on student.Num=score.Stu_id;

通过上面这三种方法就可以把不同的表连接到一起,变成一张大表,之后的查询操作就简单一些了。

而对于select * from student,score;则尽量不使用此语句,产生的结果过于繁琐。

二、内连接

join 或 inner join

SQL语句:select * from student inner join score on student.Num=score.Stu_id;

此时的语句就相当于:select * from student,score where student.ID=course.ID;

三、交叉连接

cross join,没有where指定查询条件的子句的交叉联接将产生两表的笛卡尔积。

SQL语句:select * from student cross join score;

搜索更多有关“sql关联表查询语句”的信息 [百度搜索] [SoGou搜索] [头条搜索] [360搜索]
CopyRight © 2009-2024 藏獒宠物网 All Rights Reserved. 手机版