MySQL的DQL

数据查询的语法结构

select 子句1
from 子句2
[where 表达式1]
[group by 子句3]
[having 表达式2]
[order by 子句4]
[union 运算符]
[into outfile 输出文件名]
[limit [m,]n];

limit [m,] n :m是结果集中的下标,n是查询数量

1、匹配符like
通配符

  • %:任意多个字符,M%,%M,%M%
  • _:单个字符,_M

当匹配串不包含通配符,用=取代like,用<>取代not like

2、正则表达式

where 字段名 regexp '模式串'

3、空值查询

where 字段 is [not] null

4、连接查询

  1. 交叉连接
select [all | distinct] * from table1,table2
  1. 内连接
select A.*, B.*  
from student A, sc B
where A.sno = B.sno;
或者
select A.*, B.*
from student A inner join sc B on A.sno = B.sno;
  1. 自连接
select A.sno
from sc A, sc B
where A.sno = B.sno and A.cno = 'C01' and B.cno = 'C04';
  1. 外连接:左外连接、右外连接、全外连接
select [all | distinct] *
from table1 left|right|full[outer] join table2
on table1.sno = table2.sno;

5、嵌套查询

  • 不相关子查询
    • 子查询返回单值:=
    • 子查询返回值列表:in 、not in 、any、 some 、all
  • 相关子查询:子查询依赖父查询
select sname 
from student
where exists(
	select * 
	from sc
	where sno = student.sno and cno='C01';
)

6、集合查询
union intersect minus

参考资料:《MySQL数据库原理及应用》武洪萍

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值