只检索所需数据需要指定搜索条件,搜索条件也称为过滤条件。
这里使用where语句过滤需要的数据:
select prod_name, prod_price
from Products
where prod_price = 3.49;
这里的where使检索的数据仅返回prod_price=3.49的行。
在同时使用order by和where子句时,order by 子句始终位于where之后。
where子句操作符:
检查单个值:
select prod_name, prod_price
from Products
where prod_price < 10;
将所有小于10的值检索出来。
不匹配检查:
select vend_id, prod_name
from Products
where vend_id <> 'DLL01';
这里将检索出id不为DLL01的所有值。同样也可以使用!=表示不等于。
范围值检查:
select prod_name, prod_price
from Products
where prod_price between 5 and 10;
使用between关键字表示取之间值,这里仅检索出价格在5-10之间的数据。
空值检查:
select prod_name
from Products
where prod_price is null;
这条语句返回所有没有价格的数据,空的prod_price字段,不是价格为0。