文章目錄
注意:不要用應用過濾,而用SQL過濾
因爲
- SQL纔是操作數據庫最高效的語言,客戶源開發語言操作低效
- 服務器把大量未經過濾的數據通過網絡傳給客戶端,浪費網絡資源
WHERE 子句(在from子句後)
where子句的條件操作符
好多奇怪的長相
示例1:<, <=
select prod_name, prod_price
from products
where prod_price < 5;
示例2:相等檢驗
檢索兩列,不返回所有行
select prod_name, prod_price
from products
where prod_price = 3.49;
示例3:不匹配檢查
select vend_id, prod_name
from products
where vend_id <>'DLL01';
注意就算是字符串,也是單引號
mysql也支持!=表示不等於
select vend_id, prod_name
from products
where vend_id !='DLL01';
示例4:範圍檢查,between
select prod_name, prod_price
from products
where prod_price between 5 and 10;
示例5:空值檢查(where子句的is null子句)
原來子句還可以有子句
select prod_name
from products
where prod_price is null;
select cust_name
from customers
where cust_email is null;
總結
介紹瞭如何用SELECT語句的WHERE子句過濾返回的數據。
學習瞭如何檢驗相等、不相等、大於、小於、值的範圍以及NULL值等。
關鍵字
- where
- between
- and