Home >Database >SQL >How to write not equal to a certain condition in sql

How to write not equal to a certain condition in sql

下次还敢
下次还敢Original
2024-05-01 23:33:47876browse

NO condition can be used in SQL if it is not equal to a certain condition. For example: not equal to a certain value: WHERE column_name <> value; not equal to the value in the list: WHERE column_name NOT IN (list); not equal to the subquery result: WHERE column_name <> (subquery).

How to write not equal to a certain condition in sql

How to write not equal to a certain condition in SQL

In SQL, not equal to a certain condition can be used The following syntax:

<code class="sql">NOT condition</code>

where condition is the condition that needs to be negated.

Example 1: Not equal to a certain value

For example, to query all records that are not equal to 10, you can use the following query:

<code class="sql">SELECT * FROM table_name WHERE column_name <> 10;</code>

Example 2: Not equal to the value in a list

To query all records that are not equal to (10, 20, 30), you can Use the following query:

<code class="sql">SELECT * FROM table_name WHERE column_name NOT IN (10, 20, 30);</code>

Example 3: Not equal to a subquery

To query all records in the results returned by the not equal to subquery, you can use the following query:

<code class="sql">SELECT * FROM table_name WHERE column_name <> (SELECT column_name FROM other_table_name WHERE condition);</code>

The above is the detailed content of How to write not equal to a certain condition in sql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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