Home > Database > Mysql Tutorial > Does NOT EQUAL exist in MySQL?

Does NOT EQUAL exist in MySQL?

WBOY
Release: 2023-09-05 20:41:07
forward
1318 people have browsed it

MySQL 中不存在 NOT EQUAL 吗?

Yes, NOT EQUAL exists in MySQL in the form of the operator. The syntax is as follows -

SELECT * FROM yourTableName WHERE yourColumnName <> yourValue;
Copy after login

To understand the above syntax, let us create a table. The query to create the table is as follows -

mysql> create table DoesNotEqualDemo
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> Name varchar(20),
   -> PRIMARY KEY(Id)
   -> );
Query OK, 0 rows affected (0.98 sec)
Copy after login

Use the insert command to insert some records in the table. The query to insert records is as follows -

mysql> insert into DoesNotEqualDemo(Name) values(NULL);
Query OK, 1 row affected (0.24 sec)

mysql> insert into DoesNotEqualDemo(Name) values(&#39;John&#39;);
Query OK, 1 row affected (0.18 sec)

mysql> insert into DoesNotEqualDemo(Name) values(&#39;Carol&#39;);
Query OK, 1 row affected (0.43 sec)

mysql> insert into DoesNotEqualDemo(Name) values(&#39;Bob&#39;);
Query OK, 1 row affected (0.13 sec)

mysql> insert into DoesNotEqualDemo(Name) values(&#39;&#39;);
Query OK, 1 row affected (0.13 sec)

mysql> insert into DoesNotEqualDemo(Name) values(&#39;Larry&#39;);
Query OK, 1 row affected (0.13 sec)

mysql> insert into DoesNotEqualDemo(Name) values(NULL);
Query OK, 1 row affected (0.10 sec)
Copy after login

Use the select statement to display all records in the table. The query is as follows-

mysql> select *from DoesNotEqualDemo;
Copy after login

The following is the output-

+----+-------+
| Id | Name  |
+----+-------+
|  1 | NULL  |
|  2 | John  |
|  3 | Carol |
|  4 | Bob   |
|  5 |       |
|  6 | Larry |
|  7 | NULL  |
+----+-------+
7 rows in set (0.00 sec)
Copy after login

Here is the query to select all records that are not equal to NULL and empty string-

mysql> select *from DoesNotEqualDemo where Name <> &#39;NULL&#39; and Name <> &#39;&#39;;
Copy after login

The following is the output-

+----+-------+
| Id | Name  |
+----+-------+
|  2 | John  |
|  3 | Carol |
|  4 | Bob   |
|  6 | Larry |
+----+-------+
4 rows in set (0.00 sec)
Copy after login

The above is the detailed content of Does NOT EQUAL exist in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template