MySQL数据库3

连接查询

分类:内连接、外连接、多表连接、自连接、子查询

内连接:
select 字段名 from 表1 别名1 inner join 表2 别名2 on 连接条件 where 条件式1 group by 字段名 having 条件式2 order by 字段名 排序 limit 数字;
或者  
select 字段名 from 表1 别名1,表2 别名2 where 连接条件 
外链接:
左(右)(全)外连接:select 字段名 from 表1 left(right)(full)[outer] join 表2 on 连接条件
注:MySQL不支持全连接
多表连接:
select * from 表1 inner(left)join 表2 on 连接条件 inner(left)join 表3 on 连接条件...
或者
select * from 表1,表2,表3 where 连接条件 and 连接条件 and 连接条件...
自连接:

在一个表中,自己和自己连接

子查询:

把某个select结果当做一个值或一张表,做进一步的查询

猜你喜欢

转载自blog.csdn.net/Eternity_y/article/details/82080849