Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

Not equal to (Transact-SQL) - traditional

Applies to: 👁 Image
SQL Server 👁 Image
Azure SQL Database 👁 Image
Azure SQL Managed Instance 👁 Image
Azure Synapse Analytics 👁 Image
Analytics Platform System (PDW) 👁 Image
SQL analytics endpoint in Microsoft Fabric 👁 Image
Warehouse in Microsoft Fabric 👁 Image
SQL database in Microsoft Fabric

Compares two expressions (a comparison operator). When you compare non-null expressions, the result is TRUE if the left operand isn't equal to the right operand. Otherwise, the result is FALSE. If either or both operands are NULL, see SET ANSI_NULLS.

👁 Image
Transact-SQL syntax conventions

Syntax

expression <> expression

Arguments

expression

Any valid expression. Both expressions must have implicitly convertible data types. The conversion depends on the rules of data type precedence.

Return types

Boolean

Examples

The code samples in this article use the AdventureWorks2025 or AdventureWorksDW2025 sample database, which you can download from the Microsoft SQL Server Samples and Community Projects home page.

A. Use <> in a simple query

The following example returns all rows in the Production.ProductCategory table that don't have a value in ProductCategoryID that equals 3 or 2.

SELECT ProductCategoryID,
 Name
FROM Production.ProductCategory
WHERE ProductCategoryID <> 3
 AND ProductCategoryID <> 2;

Here's the result set.

ProductCategoryID Name
------------------ ----------------------
1 Bikes
4 Accessories

Related content


Feedback

Was this page helpful?

Additional resources