You should use IS NOT NULL. (The comparison operators = and <> both give UNKNOWN with NULL on either side of the expression.)

CopySELECT * 
FROM table 
WHERE YourColumn IS NOT NULL;

Just for completeness I'll mention that in MySQL you can also negate the null safe equality operator but this is not standard SQL.

CopySELECT *
FROM table 
WHERE NOT (YourColumn <=> NULL);

Edited to reflect comments. It sounds like your table may not be in first normal form in which case changing the structure may make your task easier. A couple of other ways of doing it though...

CopySELECT val1 AS val
FROM  your_table
WHERE val1 IS NOT NULL
UNION ALL
SELECT val2 
FROM  your_table
WHERE val2 IS NOT NULL
/*And so on for all your columns*/

The disadvantage of the above is that it scans the table multiple times once for each column. That may possibly be avoided by the below but I haven't tested this in MySQL.

CopySELECT CASE idx
         WHEN 1 THEN val1
         WHEN 2 THEN val2
       END AS val
FROM   your_table
        /*CROSS JOIN*/
       JOIN (SELECT 1 AS idx
                   UNION ALL
                   SELECT 2) t
HAVING val IS NOT NULL  /*Can reference alias in Having in MySQL*/
Answer from Martin Smith on Stack Overflow
🌐
W3Schools
w3schools.com › sql › sql_null_values.asp
SQL NULL Values - IS NULL and IS NOT NULL
The IS NOT NULL operator is used to test for non-empty values (NOT NULL values). The following SQL lists all customers with a value in the "Address" field:
🌐
Mimo
mimo.org › glossary › sql › is-not-null
SQL IS NOT NULL Condition: Syntax, Usage, and Examples
The SQL IS NOT NULL condition checks whether a column contains a value rather than being empty. In SQL, a NULL represents missing or undefined data—not the number zero, an empty string, or false.
Discussions

Need some knowledge on NULL and NOT NULL
a null is used for multiple purposes -- for example, not known, not applicable, etc. theoreticians take great joy in debating which uses are valid, and whether they can be substituted by some non-null placeholder suffice to say, a null is used when you don't know what value should go there if you don't want that situation to arise, just make the column NOT NULL and you'll never be able to not insert an actual value More on reddit.com
🌐 r/SQL
33
14
December 22, 2021
sql - MySQL SELECT only not null values - Stack Overflow
Just for completeness I'll mention that in MySQL you can also negate the null safe equality operator but this is not standard SQL. More on stackoverflow.com
🌐 stackoverflow.com
if statement - MySQL IF NOT NULL, then display 1, else display 0 - Stack Overflow
I'm working with a little display complication here. I'm sure there's an IF/ELSE capability I'm just overlooking. I have 2 tables I'm querying (customers, addresses). The first has the main reco... More on stackoverflow.com
🌐 stackoverflow.com
how works "not in" with nulls value?
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions. ... Here is a more long-winded explanation which takes it step by step. We have: select * from tab1 where col1 not in (select col2 from tab2) We can replace the subquery with the values in tab2. This gives us: select * from tab1 where col1 not in (1, null... More on learn.microsoft.com
🌐 learn.microsoft.com
2
0
December 9, 2021
🌐
Hightouch
hightouch.com › sql-dictionary › sql-is-not-null
SQL IS NOT NULL - Syntax, Use Cases, and Examples | Hightouch
December 29, 2023 - The SQL IS NOT NULL operator is used to filter rows in a database table where a specified column's value is not NULL. It is the opposite of the IS NULL operator.
🌐
Reddit
reddit.com › r/sql › need some knowledge on null and not null
r/SQL on Reddit: Need some knowledge on NULL and NOT NULL
December 22, 2021 -
  • Where and why exactly a null is used?

  • What is exactly null and not null? To my understanding Not null we use when its mandatory to insert some value in that field, also when we give check constraint so by default the column will be not null right?

  • By adding new column through alter method default values are null, so how would I be able to insert values in it and is it right to give not null constraint to that new column while adding through alter method, basically when null and when not null to be used?...

god this is so confusing please help me, ik im asking alot but im really confused

🌐
Programiz
programiz.com › sql › is-null-not-null
SQL IS NULL and IS NOT NULL (With Examples)
In SQL, IS NULL and IS NOT NULL are used to check if a column in a table contains a NULL value or not.
🌐
GeeksforGeeks
geeksforgeeks.org › sql › sql-is-not-null-operator
SQL IS NOT NULL Operator - GeeksforGeeks
July 23, 2025 - In SQL, the IS NOT NULL operator is a powerful logical operator used to filter data by identifying rows with non-NULL values in specified columns. This operator works opposite to the IS NULL operator, returning TRUE for rows where the value ...
Find elsewhere
Top answer
1 of 12
542

You should use IS NOT NULL. (The comparison operators = and <> both give UNKNOWN with NULL on either side of the expression.)

CopySELECT * 
FROM table 
WHERE YourColumn IS NOT NULL;

Just for completeness I'll mention that in MySQL you can also negate the null safe equality operator but this is not standard SQL.

CopySELECT *
FROM table 
WHERE NOT (YourColumn <=> NULL);

Edited to reflect comments. It sounds like your table may not be in first normal form in which case changing the structure may make your task easier. A couple of other ways of doing it though...

CopySELECT val1 AS val
FROM  your_table
WHERE val1 IS NOT NULL
UNION ALL
SELECT val2 
FROM  your_table
WHERE val2 IS NOT NULL
/*And so on for all your columns*/

The disadvantage of the above is that it scans the table multiple times once for each column. That may possibly be avoided by the below but I haven't tested this in MySQL.

CopySELECT CASE idx
         WHEN 1 THEN val1
         WHEN 2 THEN val2
       END AS val
FROM   your_table
        /*CROSS JOIN*/
       JOIN (SELECT 1 AS idx
                   UNION ALL
                   SELECT 2) t
HAVING val IS NOT NULL  /*Can reference alias in Having in MySQL*/
2 of 12
25

You can filter out rows that contain a NULL value in a specific column:

CopySELECT col1, col2, ..., coln
FROM yourtable
WHERE somecolumn IS NOT NULL

If you want to filter out rows that contain a null in any column then try this:

CopySELECT col1, col2, ..., coln
FROM yourtable
WHERE col1 IS NOT NULL
AND col2 IS NOT NULL
-- ...
AND coln IS NOT NULL

Update: Based on your comments, perhaps you want this?

CopySELECT * FROM
(
    SELECT col1 AS col FROM yourtable
    UNION
    SELECT col2 AS col FROM yourtable
    UNION
    -- ...
    UNION
    SELECT coln AS col FROM yourtable
) T1
WHERE col IS NOT NULL

And I agre with Martin that if you need to do this then you should probably change your database design.

🌐
DB Vis
dbvis.com › thetable › sql-is-not-null-condition-definitive-guide
SQL IS NOT NULL Condition: Definitive Guide
August 13, 2025 - This checks whether the SQL expression (a column, hardcoded value, or other type of expression) is a NULL value. If the value of the expression holds NULL, the condition returns false.
🌐
Oracle
docs.oracle.com › en › database › other-databases › nosql-database › 25.3 › sqlreferencefornosql › is-null-and-is-not-null-operators.html
IS NULL and IS NOT NULL Operators
February 6, 2026 - If the input expression returns more than one item, an error is raised. If the result of the input expression is empty, IS NULL returns false. Otherwise, IS NULL returns true if and only if the single item computed by the input expression is NULL. The IS NOT NULL operator is equivalent to NOT ...
🌐
Medium
medium.com › @roscoe.kerby › sql-exploring-the-difference-between-null-and-is-not-null-33602745e60e
SQL: Exploring the Difference Between “!= NULL” and “IS NOT NULL” | by Roscoe Kerby [ROSCODE] | Medium
September 26, 2023 - You might expect this query to return all employees who have a department_id value that is not NULL. However, it won’t return any rows because NULL values are not directly comparable using the “!=” operator. In SQL, comparisons with NULL typically result in an unknown or NULL result.
🌐
IBM
ibm.com › docs › en › informix-servers › 14.10.0
IS NULL and IS NOT NULL Conditions - IBM Documentation
January 21, 2026 - Conversely, if you use the IS NOT NULL operator, the condition is satisfied when the column contains a value that is not null, or when the expression that immediately precedes the IS NOT NULL keywords does not evaluate to null.
🌐
W3Schools
w3schools.com › sql › sql_notnull.asp
SQL NOT NULL Constraint
CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255) NOT NULL, Age int ); To define a NOT NULL constraint on an existing table, use ALTER TABLE and add NOT NULL after the data type of the column name.
Top answer
1 of 2
1

Here is a more long-winded explanation which takes it step by step. We have:

select * from tab1 where col1 not in (select col2 from tab2)

We can replace the subquery with the values in tab2. This gives us:

select * from tab1 where col1 not in (1, null, 6 ,4, 7)

Let's move the NOT:

select * from tab1 where not (col1 in (1, null, 6 ,4, 7))

IN is just a shortcut for OR, so what we really have is:

select * from tab1 where NOT (col1 = 1 OR col1 = null OR col1 = 6 OR col = 4 OR col1 = 7)

Let's nu study this for some of the values for tab1.col1. We can start with 1. This gives us

NOT (1 = 1 OR ...)

and we can stop there. The list of OR will return TRUE and with NOT in front we get FALSE.

What if we try 5?

NOT (5= 1 OR 5 = null OR 5 = 6 OR 5 = 4 OR 5 = 7)

so that's

NOT (FALSE OR 5 = NULL OR FALSE OR FALSE OR FALSE)

What about 5 = NULL? Well NULL is an unknown value. It could be different from 5, but by chance it could be 5. So the outcome is not TRUE, not FALSE, but UNKNOWN. So we have:

NOT (FALSE OR UNKNOWN OR FALSE OR FALSE OR FALSE)

The result of all the OR is UNKNOWN and with NOT in front, the value is still UNKNOWN by the three-valued logic of SQL. But for WHERE to include a row, the condition for the row must be TRUE, and thus the row with 5 is filtered out as well.

Using NOT EXISTS as Dan showed is a very good solution. Not the least since [NOT] EXISTS is more powerful than IN. However, there is a simpler fix to the original query:

select * from tab1 where col1 not in (select col2 from tab2 WHERE col2 IS NOT NULL)
2 of 2
1

It's SQL specification or bug?

The unintuitive behavior of NOT IN is part of the SQL standard specification. The SQL Server documentation includes this caution:

Any null values returned by subquery or expression that are compared to test_expression using IN or NOT IN return UNKNOWN. Using null values in together with IN or NOT IN can produce unexpected results.

The gotcha is that UNKNOWN is neither TRUE nor FALSE when NULL values are returned so the NOT IN predicate will never evaluate to either true or false . You may find NOT EXISTS is more intuitive because it will return only TRUE or FALSE.

SELECT *  
FROM tab1   
WHERE NOT EXISTS (  
    SELECT 1   
    FROM tab2  
    WHERE tab2.col2 = tab1.col1  
);  
🌐
TechOnTheNet
techonthenet.com › sql_server › is_not_null.php
SQL Server: IS NOT NULL Condition
INSERT INTO contacts (contact_id, last_name, first_name) SELECT employee_id, last_name, first_name FROM employees WHERE last_name IS NOT NULL; This SQL Server IS NOT NULL example will insert records into the contacts table where the last_name does not contain a null value in the employees table.
🌐
Tutorialspoint
tutorialspoint.com › sql › sql-is-not-null.htm
SQL - IS NOT NULL Operator
The IS NOT NULL operator in SQL is used to check whether a column contains a non-null value. In SQL, NULL represents missing, undefined, or unknown data, it is not the same as zero, an empty string, or a space.
🌐
W3Schools
w3schools.com › sql › sql_ref_not_null.asp
SQL NOT NULL
String Functions: Asc Chr Concat ... SQL Study Plan SQL Bootcamp SQL Training ... The NOT NULL constraint enforces a column to not accept NULL values, which means that you cannot insert or update a record without adding a value ...
🌐
Quora
quora.com › What-is-the-SQL-IS-NOT-NULL-condition-and-how-is-it-used
What is the SQL IS NOT NULL condition and how is it used? - Quora
Answer (1 of 4): IS NULL and IS NOT NULL are substitutes for the “=” sign. Equations are for stating that everything on the left side of the equation evaluates to the same thing as everything on the right side.
🌐
Quora
quora.com › What-is-the-difference-between-IS-NOT-NULL-and-NULL-in-SQL
What is the difference between 'IS NOT NULL' and '<> NULL' in SQL? - Quora
Answer: In SQL, a comparison between a [code ]null[/code] value and any other value (including another [code ]null[/code]) a using a logical operator (eg [code ]=[/code], [code ]!=[/code], [code ]