使用select语句的where子句指定搜索条件
- 使用where子句
select prod_name,prod_price
from products
where prod_price = 2.50;
#检索两个列,返回prod_price值为2.50的行
#where子句在from之后
#若order by和where同时使用,则order by在where之后
- where子句操作符
mysql支持的所有条件操作符
操作符 | 说明 |
---|---|
= | 等于 |
<> | 不等于 |
!= | 不等于 |
< | 小于 |
<= | 小于等于 |
> | 大于 |
>= | 大于等于 |
between | 在指定两个值之间 |
#1 检测单个值
select prod_name,prod_price
from products
where prod_name = 'fuses';
#执行匹配时默认不区分大小写
select prod_name,prod_price
from products
where prod_price < 10;
#2 不匹配检查
select vend_id,prod_name
from products
where vend_id !=(或<>) 1003;
#单引号用来限定字符串,与数值进行比较则不需要引号
#3 范围值检查
select prod_price,prod_name
from products
where prod_price between 5 and 10;
#包括开始值和结束值
#4 空值检查
select prod_name
from products
where prdo_price is null;
#null与字段包含0,空字符串或仅仅包含空格是不同的
select cust_id
from customers
where cust_email is null;