MySQL查询条件常见用法详解
16lz
2021-12-20
本文实例讲述了MySQL查询条件常见用法。分享给大家供大家参考,具体如下:
条件
使用where子句对表中的数据筛选,结果为true的行会出现在结果集中
语法如下:
select * from 表名 where 条件;
select * from students where id=1;
比较运算符
逻辑运算符
模糊查询
范围查询
空判断
比较运算符
等于: =
大于: >
大于等于: >=
小于: <
小于等于: <=
不等于: != 或 <>
例1:查询编号大于3的学生
select * from students where id > 3;
select * from students where id <= 4;
select * from students where name != '黄蓉';
select * from students where is_delete=0;
and
or
not
例5:查询编号大于3的女同学
select * from students where id > 3 and gender=0;
select * from students where id < 4 or is_delete=0;
like
%表示任意多个任意字符
_表示一个任意字符
例7:查询姓黄的学生
select * from students where name like '黄%';
select * from students where name like '黄_';
select * from students where name like '黄%' or name like '%靖';
in表示在一个非连续的范围内
例10:查询编号是1或3或8的学生
select * from students where id in(1,3,8);
例11:查询编号为3至8的学生
select * from students where id between 3 and 8;
select * from students where (id between 3 and 8) and gender=1;
注意:null与''是不同的
判空is null
例13:查询没有填写身高的学生
select * from students where height is null;
例14:查询填写了身高的学生
select * from students where height is not null;
select * from students where height is not null and gender=1;
优先级由高到低的顺序为:小括号,not,比较运算符,逻辑运算符
and比or先运算,如果同时出现并希望先算or,需要结合()使用
更多关于MySQL相关内容感兴趣的读者可查看本站专题:《MySQL查询技巧大全》、《MySQL常用函数大汇总》、《MySQL日志操作技巧大全》、《MySQL事务操作技巧汇总》、《MySQL存储过程技巧大全》及《MySQL数据库锁相关技巧汇总》
希望本文所述对大家MySQL数据库计有所帮助。
更多相关文章
- MySQL系列多表连接查询92及99语法示例详解教程
- Android(安卓)- Manifest 文件 详解
- Android的Handler机制详解3_Looper.looper()不会卡死主线程
- Selector、shape详解(一)
- android2.2资源文件详解4--menu文件夹下的菜单定义
- Android发送短信方法实例详解
- Android(安卓)读取资源文件实例详解
- 详解Android中的屏幕方向
- Android学习笔记(10)————Android的Listview详解1(ArrayAdapte