SQL高级查询

高级查询:

一、多表链接

1,普通查询

select * from 表名,表名 where 表名.列名 = 表名.列名

2,join链接

select * from 表名 join 表名 on 表名.列名 = 表名.列名

二、多表联合

select * from 表名 where 列名='内容' union select * from 表名 where 列名='内容'

三、子查询(无关子查询)

select * from 表名 where 列名 = (select 列名 from 表名 where 列名='内容') 查单条数据用= !=非此条数据之外的内容

select * from 表名 where 列名 not in (select 列名 from 表名 where 列名='内容' 列名 = '内容') 查多条数据用in not就是非此类条件

四、子查询(相关子查询)

select * from 表名 定义名 where 定义名.列名<(select avg(列名)from 表名 定义名 where 定义名.列名 = 定义名.列名)

原文地址:https://www.cnblogs.com/liaoliao/p/5136765.html