是的,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 嗎?的詳細內容。更多資訊請關注PHP中文網其他相關文章!