MySQL-SQL查询

1.基础

范围查询

between:select 字段 from 表名 where 字段 between 值 and 值;
select id from stu where id between 1 and 3;

in:select 字段 from 表名 where 字段 in (值,值);
select id from stu where id in (2,3);

not in:select 字段 from 表名 where 字段 in (值,值);
select id from stu where id not in (2,3);

排序

order by asc:select 字段 from 表名 order by 字段;(升序)
select * from stu order by id;

order by desc:select 字段 from 表名 order by 字段 desc;(降序)
select * from stu order by id;

去重

distinct:select distinct(字段) from 表名;
select distinct(id) from stu;

限制

limit:select 字段 from 表名 limit 数字;
select * from stu limit 2;

猜你喜欢

转载自www.cnblogs.com/zhangshan33/p/12303396.html