MySQL学习笔记7:基本查询
2013-05-01 23:04
681 查看
参考表:student
多字段查询
所有字段查询
where指定查询
in指定集合查询
not in非范围查询
between and指定范围查询
not between and不在指定范围的查询
like字符串匹配查询
not like不匹配查询
null查询
and多条件查询
or多条件查询
distinct查询结果不重复
order by查询结果排序
group by分组查询
正则表达式查询
limit限制查询结果数量
多字段查询
mysql> select id,name,birth from student;
所有字段查询
mysql> select * from student;
where指定查询
mysql> select * from student where id=901; mysql> select * from student where id>=904; mysql> select name from student where department='计算机系';
in指定集合查询
mysql> select * from student where birth in(1988,1990); mysql> select * from student where id in(903,906);
not in非范围查询
mysql> select * from student where birth not in(1990,1998);
between and指定范围查询
mysql> select * from student where birth between 1986 and 1988;
not between and不在指定范围的查询
mysql> select * from student where id not between 904 and 906;
like字符串匹配查询
mysql> select * from student where name like '_三'; mysql> select * from student where name like '张三'; mysql> select * from student where name like '张%';
not like不匹配查询
mysql> select * from student where name not like '张%';
null查询
mysql> select * from student where address is null;
and多条件查询
mysql> select * from student where name like '张%' and birth>1985; mysql> select * from student where name like '张%' and birth>1985 and id like '%3';
or多条件查询
mysql> select * from student where id=905 or birth=1988; mysql> select * from student where id=905 or birth=1988 or sex='女';
distinct查询结果不重复
mysql> select distinct sex from student; mysql> select distinct department from student;
order by查询结果排序
mysql> select * from student order by birth; mysql> select * from student order by birth asc; mysql> select * from student order by birth desc;
group by分组查询
mysql> select sex,group_concat(name) from student group by sex; mysql> select sex,count(name) from student group by sex;
正则表达式查询
mysql> select * from student where birth regexp '1988|1990';
limit限制查询结果数量
mysql> select * from student limit 2; mysql> select * from student limit 1,3;
相关文章推荐
- mysql学习笔记-创建用户以及登录,基本信息查询
- MySQL中的基本查询语句学习笔记
- MySQL中的基本查询语句学习笔记
- MySQL学习笔记7:基本查询
- 5.笔记 MySQL学习——mysql基本显示查询
- MySQL学习笔记-子查询和连接
- MySql官方手册学习笔记2 MySql的模糊查询和正则表达式
- (学习笔记)MySQL基本操作语句
- MySQL学习笔记20150923基本概念与数据库和表的创建
- MySQL学习笔记——对查询结果进行排序
- MYSQL的学习笔记------MYSQL的基本语法
- sql分类及基本sql操作,校对规则(mysql学习笔记二)
- [MySQL]学习笔记- 用户行为表中,查询每个人的一条最新行为(分组 排序 取时间最大的一条记录)
- MySQL 基础得不能再基础的基本语句【学习笔记】
- mysql 学习笔记--基本命令练习
- MySQL中查询日志与慢查询日志的基本学习教程
- 57.笔记 MySQL学习——查询扩展全文搜索
- mysql 数据库笔记-基本查询(分组、聚合函数)
- Mysql学习笔记二——基础查询where练习
- 【MYSQL数据库】MYSQL学习笔记-mysql分区基本操作