The Not Equal Operator
SQL supports the following symbols to denote the not equal operator: !=
and <>
. The not equal operator will exclude the conditions where values are equal in the results.
Exercise 5.03: Using the != and <> Operators
The store manager realizes that the tomato sauce received has gone bad, so he does not want to present it in the list of available items. To write a query to display all the products except the tomato sauce, perform the following steps:
- Enter the
SELECT
statement, using theWHERE
clause and the!=
operator:SELECT ProductName,NetRetailPrice FROM Products WHERE ProductName != 'tomato sauce' ORDER BY NetRetailPrice;
- Execute the query; you should see the following results:
- As an alternative, now replace the
!=
symbol with the<>
operator:SELECT ProductName,NetRetailPrice FROM Products WHERE ProductName <> 'tomato...