MySQL数据库学习(六)where条件,模糊查询,联表查询

1、where条件子句
作用:检索数据库中符合条件的值

逻辑运算符:
and && a&&b ,a and b
or || a||b ,aorb
not ! not a , !a

2、模糊查询

比较运算符:
is noll//如果为空,则为真

is not null//如果不为空,则为真

between and//在a 和 b 之间,则为真
例:
select * from student where 成绩 between 95 and 100;//成绩在95到100之间

like //a like b 如果a匹配b,则为真
例:有两种为'%',代表0或者任意个字符,'_'代表一个字符
select * from student where name like '华%';//查询姓华的同学
select * from student where name like '%华%';//查询名字中带有'华'字的同学
select * from student where name like '华_';//查询姓华的同学,名字后面只有一个字的

in //a in (a1,a2,a3),满足其中一个,则为真
例:
select * from student where id in (1,2,3);//查询编号在1,2,3其中一个

3、联表查询

左查询:left join
右查询:right join
自连接:inner join

操作描述
inner join如果表中至少有一个表匹配就返回结果
left join会从左表中返回结果,即使右表中没有匹配的数据
right join会从右表中返回结果,即使左表中没有匹配的数据

4、自连接
自己的表和自己的表连接,核心:一张表拆为两张一样的表即可

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值