本文实例讲述了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数据库计有所帮助。

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. Android(安卓)- Manifest 文件 详解
  3. Android的Handler机制详解3_Looper.looper()不会卡死主线程
  4. Selector、shape详解(一)
  5. android2.2资源文件详解4--menu文件夹下的菜单定义
  6. Android发送短信方法实例详解
  7. Android(安卓)读取资源文件实例详解
  8. 详解Android中的屏幕方向
  9. Android学习笔记(10)————Android的Listview详解1(ArrayAdapte

随机推荐

  1. HashMap的负载因子初始值为什么是0.75?这
  2. 格式化Curl返回的Json工具
  3. 大数据开发工程师完结
  4. 八大基础排序总结
  5. Android高频面试专题 - 基础篇(一)Activity
  6. ConcurrentHashMap之size()方法
  7. java都为我们提供了各种锁,为什么还需要分
  8. Java线程之线程的调度-让步
  9. 常用控件的使用方法(参考书籍'第一行代码'
  10. mysql中的合并表和分区表详解(经常使用的