PostgreSQL – Not Equal (!=) Operator

In PostgreSQL, the not equal to operator (<> or !=) is a comparison operator used to check if two values are not equal. It is used to filter rows where a specified condition is not met.

The syntax for using the not equal to operator is as follows:

SELECT columns FROM table_name WHERE column_name <> value;

Here’s an example of using the not equal to operator:

SELECT product_name, price FROM products WHERE category <> 'Electronics';

In this example, the query retrieves the product name and price for products that do not belong to the ‘Electronics’ category.

You can also use the != operator as an alternative to <>:

SELECT name, salary FROM employees WHERE department != 'IT' AND salary != 60000;

In this example, the query retrieves the employee name and salary for employees who are not in the ‘IT’ department and don’t have a salary of $60,000.

The not equal to operator is a valuable tool for constructing queries that exclude specific values or rows that don’t meet certain conditions. It helps you narrow down your results and retrieve the data that’s relevant to your requirements.

Similar Posts