02-条件查询

使用where语句对表中的数据筛选,结果为true的行会出现在结果集中

1.语法如下:

select * from 表名 where 条件;  
 例:
select * from students where id=1;

where后面支持多种运算符,进行条件的处理

  • 比较运算符

  • 逻辑运算符

  • 模糊查询

  • 范围查询

  • 空判断

2.比较运算符

等于: =
大于: >
大于等于: >=
小于: <
小于等于: <=
不等于: != 或 <>

例1:查询编号大于3的学生
select * from students where id > 3;

例2:查询编号不大于4的学生
select * from students where id <= 4;

例3:查询姓名不是“黄蓉”的学生
select * from students where name != '黄蓉';

例4:查询没被删除的学生
select * from students where is_delete=0;

3.逻辑运算符

4.模糊查询:like

5.范围查询: in 、between

6.空判断

7.优先级

Last updated