Mysql-单表数据查询

查询条件目录:
1. distinct:去重查询
条件查询:
2. where
3. between and 
4. is null
5. is not null
集合查询
6. where 字段 in  ...
7. where 字段 not in
8. where 字段=or 字段=值
模糊查询
9.like
10.not like
排序查找
11.order by
显示限制,分页使用的较多
12.limit

查询字段去重 distinct

select 字段1,字段2,字段n distinct from 表名;

在这里插入图片描述
去重查询
在这里插入图片描述

where

select 查询字段 from 表名 where 字段>数值;
字段>数值  '>' 可以是逻辑运算符 也可以为比较运算符

查询表中id>3的数据
在这里插入图片描述

between and

between and 判断字段的数值是否在指定的范围
select * from 表名 where 字段 between 数值 and 数值;

查询id在1到3之间的数据
在这里插入图片描述

is null

查询为空的字段

select * from book where title is null;
select * from 表名 where 字段 is null;

is not null

查询不为空的字段

select * from 表名 where 字段 is not null;
select * from book where id is not null;

in

select * from 表名 where 字段 in(value,value)
 select * from book where id in (1,3);

查询id为1,3的数据
在这里插入图片描述

not in

select * from 表名 where 字段 not in(value,value..);

在这里插入图片描述

or

select * from 表名 where 字段=1 or 字段=;

在这里插入图片描述

like

模糊查找

select * from 表名 where 字段 like "值"
"_"单个字符
select * from 表名 where 字段 like "_值"
"%"多个字符
select * from 表名 where 字段 like "%值"

在这里插入图片描述

not like

模糊查找,只要不在not like 中的字段都显示

select * from 表名 where 字段 not like "值"

"_"单个字符
select * from 表名 where 字段 not like "_值"
"%"多个字符
select * from 表名 where 字段 not like "%值"

在这里插入图片描述

order by

根据字段进行排序

升序:select * from 表名 order by 字段
降序: select * from 表名 order by 字段 desc;

正序排序
查找id大于3数据,并且正序排序
在这里插入图片描述
在这里插入图片描述
降序
在这里插入图片描述

limit

select * from 表名 limit 数值;
数值代表要显示多少条

select * from 表名 limit 开始,结束;
开始代表了从第几条,如果是2,就从3开始
结束代表了 显示多少条 比如:5 从开始显示5条数据

查询到的数据,指定显示多少条
在这里插入图片描述
在这里插入图片描述

显示从大于2开始的后面的5条数据
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值