查询条件目录:
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条数据