How to Filter Rows Without Null in a Column in SQL?


To filter rows without null in a column in SQL, you can use the WHERE clause with the IS NOT NULL operator. Here are some examples:

Example 1: Using the WHERE clause with IS NOT NULL operator

Suppose you have a table named employees with columns id, name, and salary. To filter out the rows where the salary column is not null, you can use the following SQL query:

SELECT * FROM employees WHERE salary IS NOT NULL;

This query will return all the rows from the employees table where the salary column is not null.

Example 2: Using the WHERE clause with the NOT operator

You can also use the NOT operator to filter out the rows where the salary column is null. Here's an example:

SELECT * FROM employees WHERE NOT salary IS NULL;

This query will return all the rows from the employees table where the salary column is not null.

Example 3: Using the WHERE clause with the <> operator

Another way to filter out the rows where the salary column is null is to use the <> operator. Here's an example:

SELECT * FROM employees WHERE salary <> NULL;

However, this query will not return any rows because the <> operator does not work with null values. To filter out null values, you must use the IS NOT NULL operator.

In conclusion, the most common and correct way to filter out rows without null in a column in SQL is to use the WHERE clause with the IS NOT NULL operator.



About the author

William Pham is the Admin and primary author of Howto-Code.com. With over 10 years of experience in programming. William Pham is fluent in several programming languages, including Python, PHP, JavaScript, Java, C++.