你可以在 WHERE 子句中指定任何條件。 你可以使用 AND 或者 OR 指定一個或多個條件。 WHERE 子句也可以運用于 SQL 的 DELETE 或者 UPDATE 命令。 WHERE 子句類似于程序語言中的 if 條件,根據 MySQL 表中的字段值來讀取指定的數據。 示例如下:
1、按關系運算符篩選
等于 =
大于 >
大于等于>=
小于<
小于等于<=
不等于!=
例子如下
select name from student where name='張三' ## 查詢name等于張三的數據 select name from student where name!='張三' ## 查詢name不等于張三的數據 select name from student where age>20 ## 查詢age大于20的數據 2、邏輯運算符
and
or
not
例子如下
select * from student where age>10 and name='張三' ##查詢age大于10且name等于"張三"的數據。 select * from student where not name='張三' ##查詢name不等于"張三"的數據。 3、范圍查詢
in
between 大數值 and 小數值
例子如下
select * from student where age in (10,11) ##查詢age等于10或者11的數據。 select * from student where age=10 or age=11 ## 與上面語句等效。 select * from student where age between 10 and 24 ##查詢age在10到24之間的數據,包含邊界值。 4、空判斷
select * from student where address is null ##查詢address為null的數據 select * from student where address is not null ##查詢address不為null的數據 5、模糊查詢
like
%表示任意多個字符(包括0)
_表示任意一個字符
escape:取消%或_字符的通配符特性
例子如下
select * from student where name like '王%' ##查詢name中姓張的數據。 select * from student where name like '張_ ##查詢name中兩個字姓張的數據。 select * from student where name like '%A%%' escape 'A' ##查詢name中含有"%"的數據 以上就是“mysql中where查詢語句如何用”這篇文章的所有內容,感謝各位的閱讀!