MySQL条件查询
- 语法
select 查询列表
from 表名
where 筛选条件 - 执行顺序
(1)from (2)where (3)select
eg:select last_name from employee where salary>2000; - 特点:
(1)按关系表达式筛选
关系运算符:> < <= >= <>(不等于)
补充:可以用!= 但是不建议
(2)and or not
补充:也可以用 && || ! 但是不建议
(3)模糊查询
in between and is null
案例分析
一:按条件表达式分析
eg:查询工资小于15000的姓名,工资
select last_name,salary
from employees
where salary <15000;
二:按逻辑表达式分析
案例一:查询部门编号不在50-100之间的员工姓名,部门编号,邮箱。
方法一:select last_name,department_id,email from employees where department_id<50 or department_id>100;
方法二:select last_name,department_id,email from employees where not (department_id>=50 and department_id<=100);