Select name, price from products where price = 2.50;過濾出products表裏price列等於2.50的列(name,price兩列)sql
操做符spa |
說明ci |
=產品 |
等於table |
< >im |
不等於數據 |
!=tab |
不等於錯誤 |
<ab |
小於 |
< = |
小於等於 |
> |
大於 |
> = |
大於等於 |
BETWEEN |
在指定的兩個值之間 |
Select name, price from products where prod_name = ‘fuses’;按name等於fuses,輸出(name,price兩個列,MySQL執行是不區分大小寫)
Select name, price from products where prod_price < ‘10’;按price小於10的列,輸出(name,price兩個列,MySQL執行是不區分大小寫)
Select name, price from products where prod_price < = ‘10’;按price小於等於10的列,輸出(name,price兩個列,MySQL執行是不區分大小寫)
6.2.2不匹配檢查
排除供應商編號爲1003製造的全部產品
Select id, name from products where id < > 1003;
6.2.3範圍值檢查
Select name, price from products where price between 5 and 10;按price列取出5到10之間的name,price兩列內容
#注:between操做符須要用兩個值(低端值和高端值),切必須用and想連
6.2.4空值檢查
檢查表裏name列爲空的列
Select id, name, price from products where name is null;
Mysql容許給出多個where子句,子句能夠以兩種方式使用;以and子句和or 子句的方式使用
取出表中id=1003和price< = 10;的數據
Select id, name, price, from products where id = 1003 and price < = 10;
取出表中id id 等於1002,或id 等於1003的數據
Select id, name, price from products where id = 1002 or id = 1003;
價格爲10元以上,且有1002或1003的全部產品
錯誤的SQL:
Select name, price, from produtes where id = 1002 or id = 1003 and price > = 10;
#由於優先級問題(and優先級大於or的優先級)
正確的SQL:
#注:()的優先級大於and,and的優先級大於or的優先級
Select name, price, from produtes where (id = 1002 or id = 1003) and price > = 10;
用來聯絡或改變where子句中的子句的關鍵字,也稱爲邏輯操做符。