1.限制查询出数据的条数
限制查询出的数据最多为10条
select * from 表名 limit 10
2.查询出结果的前10条数据
select * from 表名 order by id limit 10
3.like运算符详解
查询用户账号以d开头的
select * from 表名 where account like "d%"
查询用户账号以d结尾的
select * from 表名 where account like "%d"
查询用户账号包含d的
select * from 表名 where account like "%d%"
查询用户账号以第二位为d的
select * from 表名 where account like "_d%"
查询用户账号以d开头,g结尾的
select * from 表名 where account like "d%g"
查询用户账号以d开头的,且至少有三位字符的
select * from 表名 where account like "d_%_%"
查询用户账号不以d开头的
select * from 表名 where account not like "d%"
4.in运算符详解
in运算符相当于多个or的组合
查询列1满足条件1及条件2的数据
select * from 表名 列1 in ("条件1","条件2")
查询列1不满足条件1及条件2的数据
select * from 表名 列1 not in ("条件1","条件2")
5.between运算符
between用于查询两个条件之间的数据
查询价格在10到20之间的商品
select * from 表名 where price between 10 and 20
6.join连接
inner join on用于将两个表关联起来
如查询成绩表中哪些科目有成绩,科目表subject,成绩表grade
内连接,选择两个表中具有匹配值的记录
select subject.name from subject inner join grade on subject.id=grade.sub_id
左连接,选择左表中具有匹配值的记录,右表中没有的话显示为空
select subject.name from subject left join grade on subject.id=grade.sub_id
右连接,选择右表中具有匹配值的记录,左表中没有的话显示为空
select subject.name from subject right join grade on subject.id=grade.sub_id