Skip to main content
Log inGet a demo
← SQL Dictionary
Comparison operators

SQL Not Equal To

What is the SQL Not Equals To Operator?

The SQL "Not Equals To" operator, denoted as "<>", "!=", or "NOT =", is used to compare values in a database table and retrieve rows where a specific column's value does not match a given criteria.

When you would use it

You would use the "Not Equals To" operator when you want to exclude rows from a database table where a column's value does not match a particular value or expression. This is particularly useful when you need to filter out specific data that does not meet your criteria.

Syntax

The basic syntax for using the "Not Equals To" operator in an SQL query is as follows:

SELECT column1, column2
FROM table_name
WHERE column_name <> value;
  • SELECT: Specifies the columns you want to retrieve.
  • FROM: Specifies the table from which you want to retrieve data.
  • WHERE: Specifies the condition for filtering rows.
  • column_name: The name of the column you want to compare.
  • value: The value or expression you want to compare the column with.

Parameter values

  • column_name: The name of the column you want to filter.
  • value: The value or expression you want to compare against.

Example query

Suppose we have a table called "products" with columns: "product_id," "product_name," and "price." Here's an example query using the "Not Equals To" operator:

SELECT product_name, price
FROM products
WHERE price <> 10.99;

In this query, we're retrieving the product names and prices of products whose price is not equal to $10.99.

Example table response

Assuming the "products" table has the following data:

product_idproduct_nameprice
1Widget A9.99
2Widget B12.99
3Widget C10.99
4Widget D8.99

The query would return:

product_nameprice
Widget A9.99
Widget B12.99
Widget D8.99

Use cases

The "Not Equals To" operator is valuable in a variety of scenarios, including:

  1. Excluding records that do not meet specific criteria, such as filtering out items that are not on sale.
  2. Finding rows that have values that are not equal to a particular reference, like locating customers who haven't made a purchase.
  3. Identifying differences between tables when performing data comparisons.

SQL languages this is available for

The "Not Equals To" operator is a common feature supported by all major SQL database management systems (DBMS) and SQL-based languages, including but not limited to:

  • MySQL
  • PostgreSQL
  • Oracle Database
  • Microsoft SQL Server
  • SQLite
  • IBM Db2

In summary, the "Not Equals To" operator is a fundamental tool for filtering and excluding data in SQL databases, and it is supported in all major SQL database systems. It provides a means to specify conditions for excluding rows that do not match your criteria.


Keep reading

SQL Equal To

Read article

SQL Greater Than

Read article

SQL Less Than

Read article

Ready to put your SQL knowledge to work?

Practice writing SQL to call data from the warehouse and sync it into Google Sheets in this 5 minute interactive demo.

Hightouch Audiences user interface.