" operator is used to express "not equal to" a certain condition. The syntax is: SELECT FROM table_name WHERE column_name <> value. For example: to find customers whose name is not equal to "John Doe": SELECT FROM customers WHERE name <> 'John Doe'; to find products whose price is not equal to 100: SELECT * FROM products WHERE price <> 100."/> " operator is used to express "not equal to" a certain condition. The syntax is: SELECT FROM table_name WHERE column_name <> value. For example: to find customers whose name is not equal to "John Doe": SELECT FROM customers WHERE name <> 'John Doe'; to find products whose price is not equal to 100: SELECT * FROM products WHERE price <> 100.">

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

How to write not equal to a certain condition in sql

下次还敢
下次还敢Original
2024-04-29 15:18:121175browse

In SQL, the "<>" operator is used to express "not equal to" a certain condition. The syntax is: SELECT FROM table_name WHERE column_name <> value. For example: to find customers whose name is not equal to "John Doe": SELECT FROM customers WHERE name <> 'John Doe'; to find products whose price is not equal to 100: SELECT * FROM products WHERE price <> 100.

How to write not equal to a certain condition in sql

How to use SQL to express "not equal to" a certain condition

In SQL, use "<> ;" operator means "not equal to".

Syntax:

<code>SELECT * FROM table_name WHERE column_name <> value</code>

The following example demonstrates how to use the "<>" operator:

<code>-- 查找所有姓名不为 "John Doe" 的客户
SELECT * FROM customers WHERE name <> 'John Doe';

-- 查找所有价格不为 100 的产品
SELECT * FROM products WHERE price <> 100;

-- 查找所有订单日期不为 "2023-03-08" 的订单
SELECT * FROM orders WHERE order_date <> '2023-03-08';</code>

Other notes:

  • The "<>" operator can also be used to compare NULL values. For example, the following query returns all customers with non-NULL names:
<code>SELECT * FROM customers WHERE name <> NULL;</code>
  • When using the "<>" operator, make sure the data types match. For example, if "column_name" is a string, then "value" must also be a string.

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