MySQL DQL语言数据查询语言

1.基本查询
select 字段,字段 。。。from 表名
as,distinct。。。
2.条件查询
select 。。。from 表名 where[查询条件]
比较运算符:>,<,>=,<=,=,!=,<>
逻辑运算符:and or not,
&&,||,!
排序:order by
聚合函数:max(),min(),count(),sum(),avg()...
分组:group by 字段
having 。。。
分页:limit start ,cont
3.多表联查
A:合并结果集
UNION,UNION ALL
B:多表联查
a)笛卡尔积
b)内连接
连接条件,检索出来的数据,都是满足连接条件。
方言:select 字段。。。from 表1 别名1 ,表2 别名2 where 别名1.字段=别名2.字段
标准:select 字段。。。from 表1 别名1 inner join 表2 别名2 on 别名1.字段=别名2.字段
自然:select 字段。。。from 表1 别名1 natural inner join 表2 别名2 
c)外连接
补充内连接的结果:
左外连接:
标准:select 字段。。。from 表1 别名1 left outer join 表2 别名2 on 别名1.字段=别名2.字段
自然:select 字段。。。from 表1 别名1 natural left outer join 表2 别名2
右外连接
标准:select 字段。。。from 表1 别名1 right outer join 表2 别名2 on 别名1.字段=别名2.字段
自然:select 字段。。。from 表1 别名1 natural right outer join 表2 别名2
全外:
左外 UNION 右外
d)自连接
一张表自己连接自己。。
4.子查询
select语句中可以在包含select语句
where,将子查询的结果作为筛选条件
from,将子查询的结果作为临时表
语法要求:1.必须(),2.不能使用order by,3.最多不能超过255。
A:单行子查询
子查询的结果,返回的结果是一条,配合:=,!=,<>,>,<,>=,<=
B:多行子查询
子查询的结果,返回的是结果是多条(看成是集合),配合:in, any,all
C:关联子查询
外层查询使用内层查询的结果,内层查询使用外层查询的内容。


猜你喜欢

转载自blog.csdn.net/weixin_42100098/article/details/80149957