Home > Database > SQL > body text

How to write not equal to a certain condition in sql

下次还敢
Release: 2024-05-01 23:33:47
Original
760 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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!

source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!