数据库查询语句
谁心中无悔,敬勇敢一杯.
1.单纯的查询
单表查询
select * from users;
单表查询指定列
select user_id,username,password from users;
指定查询条件
select * from users where user_id = 1;
2.限制查询条数(分页)
limit限制查询数目
select * from users limit 5;
查询前5条记录
select * from users limit 4,5;
从第4条记录往后查询5条记录,不包含第4
3.不重复查询(distinct)
查询指定列的所有不重复值
select distinct type from users;
4.查询记录排序(order by)
按username排序显示,limit应该放在order by 的后面,默认升序
select username from users order by username limit 5;
按降序输出
select username from users order by username desc limit 5;