符號 | 意義 |
---|---|
> | 不等于的最早用法,可移植性優于下面兩種 |
!= | 后來MySQL添加上的,類似于Java等編程語言中的不等于 |
not in | not in后面加上數據,表示不在該數據里面 |
MySQL中推薦使用>來表示不等于,為什么呢?因為可移植性強,因為查詢速度快。在leetcode上有一道題,是電影院查詢的題目,題目如下:
其實非常簡單,查詢description非boring并且id非偶數的,將查詢結果利用order by進行排序即可,但在查詢description非boring的時候要用到不等于來判斷,下面就是我使用三種不等于的查詢時間的比拼
可以看出來>還是快一些的,所以還是推薦使用>來表示不等于的
一個簡單地表數據:
select * from user where address != "北京"
select * from user where address > "北京"
select * from user where address = null
select * from user where address is null
select * from user where address != null
總結:
select * from user where address != "北京" select * from user where address > "北京" select * from user where address = null select * from user where address is null select * from user where address != null select * from user where address is not null
短短幾條語句,三個極其常見的點,或許我們在回答的時候卻不知所措,猶豫不決。
在>和!=是等價的。在某字段不等于某值(非空的值)時,輸出的結果此字段為空不輸出。
is 和 is not 用于和 null 結合,我稱它為不是,不是空
到此這篇關于MySQL 不等于的三種使用及區別的文章就介紹到這了,更多相關MySQL 不等于內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!