是的,NOT EQUAL 在 MySQL 中存在于 運算符的形式中。語法如下 –
SELECT * FROM yourTableName WHERE yourColumnName <> yourValue;
登錄后復制
為了理解上述語法,讓我們創建一個表。創建表的查詢如下 –
mysql> create table DoesNotEqualDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.98 sec)
登錄后復制
使用插入命令在表中插入一些記錄。插入記錄的查詢如下 –
mysql> insert into DoesNotEqualDemo(Name) values(NULL); Query OK, 1 row affected (0.24 sec) mysql> insert into DoesNotEqualDemo(Name) values('John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DoesNotEqualDemo(Name) values('Carol'); Query OK, 1 row affected (0.43 sec) mysql> insert into DoesNotEqualDemo(Name) values('Bob'); Query OK, 1 row affected (0.13 sec) mysql> insert into DoesNotEqualDemo(Name) values(''); Query OK, 1 row affected (0.13 sec) mysql> insert into DoesNotEqualDemo(Name) values('Larry'); Query OK, 1 row affected (0.13 sec) mysql> insert into DoesNotEqualDemo(Name) values(NULL); Query OK, 1 row affected (0.10 sec)
登錄后復制
使用 select 語句顯示表中的所有記錄。查詢如下 –
mysql> select *from DoesNotEqualDemo;
登錄后復制
以下是輸出 –
+----+-------+ | Id | Name | +----+-------+ | 1 | NULL | | 2 | John | | 3 | Carol | | 4 | Bob | | 5 | | | 6 | Larry | | 7 | NULL | +----+-------+ 7 rows in set (0.00 sec)
登錄后復制
這里是選擇所有不等于 NULL 以及空字符串的記錄的查詢 –
mysql> select *from DoesNotEqualDemo where Name <> 'NULL' and Name <> '';
登錄后復制
以下是輸出 –
+----+-------+ | Id | Name | +----+-------+ | 2 | John | | 3 | Carol | | 4 | Bob | | 6 | Larry | +----+-------+ 4 rows in set (0.00 sec)
登錄后復制
以上就是MySQL 中不存在 NOT EQUAL 嗎?的詳細內容,更多請關注www.92cms.cn其它相關文章!