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

SELECT * 
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.

SELECT *
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...

SELECT 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.

SELECT 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:
Top answer
1 of 12
541

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

SELECT * 
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.

SELECT *
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...

SELECT 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.

SELECT 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:

SELECT 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:

SELECT 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?

SELECT * 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.

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
32
14
December 22, 2021
SQL Newbie question about NOT NULL
NOT NULL in the schema context means that the data in the table must contain a value for that column. More on reddit.com
๐ŸŒ r/SQL
6
6
March 26, 2024
How to check for Is not Null And Is not Empty string in SQL server? - Stack Overflow
How can we check in a SQL Server WHERE condition whether the column is not null and not the empty string ('')? More on stackoverflow.com
๐ŸŒ stackoverflow.com
What are pros and cons of using NULLS vs NOTNULLs in database?
Pros of using NULL: When your column can be NULL, NULL is a perfect fit. Pros of using NOTNULL: When your column cannot be NULL, NOTNULL is a perfect fit. Cons of using NULL: When your column cannot be NULL, NOTNULL would be a better fit. Cons of using NOTNULL: When your column can be NULL, NULL would be a better fit. More on reddit.com
๐ŸŒ r/SQL
11
6
March 15, 2022
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ sql โ€บ is-not-null
SQL IS NOT NULL Condition: Syntax, Usage, and Examples
# SQL IS NOT NULL: 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. Use `IS NOT NULL` to return rows where values ...
๐ŸŒ
Hightouch
hightouch.com โ€บ sql-dictionary โ€บ sql-is-null
SQL IS NULL - Syntax, Use Cases, and Examples | Hightouch
December 29, 2023 - You would use the SQL IS NULL operator when you need to filter data from a table based on whether a column's value is NULL. This is useful when you want to retrieve records that lack data or records that have not been assigned a value for a ...
๐ŸŒ
Hightouch
hightouch.com โ€บ sql-dictionary โ€บ sql-is-not-null
SQL IS NOT NULL - Syntax, Use Cases, and Examples | Hightouch
December 29, 2023 - The IS NOT NULL operator allows you to select rows where a particular column contains data, ensuring that the data exists and is not missing. You would use the SQL IS NOT NULL operator when you need to filter data from a table based on whether ...
๐ŸŒ
Learning Monkey
learningmonkey.in โ€บ home โ€บ is null and is not null operators in sql
IS NULL and IS NOT NULL Operators in SQL MAde Easy Lec: 51
October 29, 2021 - IS NULL and IS NOT NULL Operators in SQL. IS NULL instructs to identify the column which have NULL values. IS NOT NULL instructs to identify the column which have NOT NULL values.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ SQl โ€บ sql_constraints.asp
SQL Constraints
ADD ADD CONSTRAINT ALL ALTER ALTER COLUMN ALTER TABLE ALTER VIEW AND ANY AS ASC BACKUP DATABASE BETWEEN CASE CHECK COLUMN CONSTRAINT CREATE CREATE DATABASE CREATE INDEX CREATE OR REPLACE VIEW CREATE TABLE CREATE PROCEDURE CREATE UNIQUE INDEX CREATE VIEW DATABASE DEFAULT DELETE DESC DISTINCT DROP DROP COLUMN DROP CONSTRAINT DROP DATABASE DROP DEFAULT DROP INDEX DROP TABLE DROP VIEW EXEC EXISTS FOREIGN KEY FROM FULL OUTER JOIN GROUP BY HAVING IN INDEX INNER JOIN INSERT INTO INSERT INTO SELECT IS NULL IS NOT NULL JOIN LEFT JOIN LIKE LIMIT NOT NOT NULL OR ORDER BY OUTER JOIN PRIMARY KEY PROCEDURE RIGHT JOIN ROWNUM SELECT SELECT DISTINCT SELECT INTO SELECT TOP SET TABLE TOP TRUNCATE TABLE UNION UNION ALL UNIQUE UPDATE VALUES VIEW WHERE MySQL Functions
๐ŸŒ
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

๐ŸŒ
TechOnTheNet
techonthenet.com โ€บ oracle โ€บ isnotnull.php
Oracle / PLSQL: IS NOT NULL Condition
This Oracle IS NOT NULL example will return all records from the customers table where the customer_name does not contain a null value.
๐ŸŒ
FastAPI
fastapi.tiangolo.com โ€บ tutorial โ€บ sql-databases
SQL (Relational) Databases - FastAPI
Field(primary_key=True) tells SQLModel that the id is the primary key in the SQL database (you can learn more about SQL primary keys in the SQLModel docs). Note: We use int | None for the primary key field so that in Python code we can create an object without an id (id=None), assuming the database will generate it when saving. SQLModel understands that the database will provide the id and defines the column as a non-null ...
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_notnull.asp
SQL NOT NULL Constraint
To define a NOT NULL constraint when creating a table, add NOT NULL after the data type of the column name. The following SQL creates a "Persons" table, and ensures that the "ID", "LastName", and "FirstName" columns cannot accept NULL values:
๐ŸŒ
Programiz
programiz.com โ€บ sql โ€บ is-null-not-null
SQL IS NULL and IS NOT NULL (With Examples)
However, space and 0 are not considered NULL. In SQL, the IS NOT NULL condition is used to select rows if the specified field is NOT NULL.
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ func_sqlserver_isnull.asp
SQL Server ISNULL() Function
SQL Examples SQL Editor SQL Quiz ... returns a specified value if the expression is NULL. If the expression is NOT NULL, this function returns the expression....
๐ŸŒ
Supabase
supabase.com โ€บ docs โ€บ reference โ€บ javascript โ€บ typescript-support
JavaScript: TypeScript support | Supabase Docs
With TypeScript, supabase-js detects things like not null constraints and generated columns. Nullable columns are typed as T | null when you select the column. Generated columns will show a type error when you insert to it. supabase-js also detects relationships between tables. A referenced table with one-to-many relationship is typed as T[]. Likewise, a referenced table with many-to-one relationship is typed as T | null.
๐ŸŒ
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. If it does not hold NULL, it returns true.
๐ŸŒ
Traininghub
traininghub.io โ€บ blog โ€บ null-and-not-null
Null and Not Null
April 4, 2024 - Definition: NOT NULL is a constraint that specifies that a column must always have a value (i.e., it cannot be NULL). Usage: You define a column as NOT NULL when you need to ensure that every record must have a value for that column. Defining a NOT NULL column: When creating or altering a table, ...
๐ŸŒ
Reddit
reddit.com โ€บ r/sql โ€บ sql newbie question about not null
r/SQL on Reddit: SQL Newbie question about NOT NULL
March 26, 2024 -

Hi! Me and my sibling-in-law are just beggining to learn SQL and are about to get in a boot camp that gives you an introductory "exam". We failed it the first time, but weren't told why. This Exam willl change, so we're not looking to have our homework done so to say, we just want to understand what we did wrong in the first try.

And after watching a lot of videos and trying different solutions, we're a bit confused about this schema:

What we can't get a grasp on is what's the use of NOT NULL here? Like, how should we add that to our querys?

We're also a bit lost when it comes to item 10, how should we use "join" here?

Thank you in advance, we're doing our best!

I'll translate all the questions so that there's some context:

The first point was:

"Write an SQL query to show all the products in the table "Productos" with a price higher to $50."
Our answer was:

Select * from productos where Price > 50

Second point was:
"Write an SQL query to obtain the total amount of orders (pedidos) made by an specific client according to his ID"
Our answer was:

Select cliente_ID, count(*) as Pedidos_count
from Pedidos
where cliente_ID= โ€˜NOT NULLโ€™
group by cliente_ID

Third point was:
"Write an SQL query to update the price of a product on the table "Productos""
Our answer was:

Update productos set price = โ€˜Floatโ€™
where nombre = โ€˜Varcharโ€™

Fourth point was:
"Write an SQL query to show the names of the products together with their corresponding categories."
Our answer was:

Select nombre_varchar, categoria_varchar from productos

Fifth point was:
"Write an SQL query to delete all the orders that have an amount lesser than 5."
Our answer was:

Delete from pedidos where quantity < 5

Sixth point was:
"Write an SQL query to calculate the total price of the orders made."
Our answer was:

Select SUM (total_precio) as "total_pedidos_precio"
From Pedidos

Seventh point was:
"Write an SQL query to show the names of the products in ascendant alphabetical order."
Our answer was:

select * from productos
Order by nombre asc

Eighth point was:
"Write an SQL query to show the orders made in a specific date." (fecha means date).
Our answer was:

select * from Pedidos where date (fecha_pedido) = NOT NULL

Ninth point was:
"Write an SQL query to obtain the average of the prices of all the products."
Our answer was:

Select AVG (precio) from Productos

Tenth point was:
"Write an SQL query to show the products together with the total amount of orders made for each one."
We weren't sure about this one, we think we have to use the join clause, but we couldn't agree on how to.

Eleventh point was:
"What's the correct syntax to insert a new record in the table "Usuarios" (Users)"
a) INSERT INTO Usuarios (Nombre, Apellido) VALUES ('John', 'Doe'); (Picked this one)
b) INSERT Usuarios (Nombre, Apellido) VALUES ('John', 'Doe');
c) INSERT VALUES ('John', 'Doe') INTO Usuarios;
d) INSERT INTO Usuarios VALUES ('John', 'Doe');

Twelfth point was:
"What's the function used to obtain the total amount of records in a table?"
a) COUNT() (Picked this one)
b) SUM()
c) AVG()
d) MAX()

Thirteenth point was:
"What's the clause used to filter results in a SELECT query?"
a) WHERE (Picked this one)
b) FROM
c) ORDER BY
d) GROUP BY

Fourteenth point was:
"What's the operator used to combine conditions in a WHERE clause?"
a) OR
b) AND (Picked this one)
c) NOT
d) XOR

Fifteenth point was:
"What's the SQL query to delete an existing table?"
a) DELETE TABLE name_table; (Picked this one)
b) DROP name_table;
c) REMOVE name_table;
d) ERASE name_table;

Top answer
1 of 5
19
NOT NULL in the schema context means that the data in the table must contain a value for that column.
2 of 5
5
Hi, In general, NOT NULL in a column defintion, means that all rows must have a value in that column. Try looking into the following point: Point 1: The query looks correct Point 2: The idea looks correct, but the syntax looks is a bit off. As the cliente_ID is NOT NULL according to your diagram, you should not need to test that this is the case. In addition, the correct syntax would be "cliente_ID is NOT NULL" Point 3 : Perhap I am misunderstanding the wording, but this does not look correct. It looks like you have confused updating the datatype of the column with updating the value of a row in the table. It looks like you are trying to update the datatype while the question asks for updating the price value for a specific product. The query should be changed to have a number in "price =" and where statement should be change to use producto_id( In order to update the price for a specific product) Point 4 to 7: They look correct Point 8: Again, it seems like an misunderstanding regarding the NOT NULL constraint. The where statement should be changed to compare against a date. Again( As in Point 2), it should not be necessary to check for NOT NULL, as it is already a part of the table definition, that it is NOT NULL. Point 9: Look correct Point 10: You are correct you should use an join between the two tables. The arrow between the tables indicate which columns you should join on. Producto_ID is the Primary Key( The column which can be used to uniquely identify rows) in productos and it is a Foreign Key( A column that refers to a Primary Key in another table) in the Pedidos table. In order to join the together, you should therefore use Producto_ID in the On clause of your join Point 11 to Point 14: Look correct Point 15: There is a difference between DELETE and DROP. DELETE is used to delete rows in table( Se for example point 5 where you used DELETE along with a filer to remove specific orders). DROP, on the other hand, is used to delete the entire table. Hope that it helps you and gives you better understanding. Happy learning! :)
๐ŸŒ
SQLS*Plus
sqlsplus.com โ€บ sql-is-not-null-condition
SQL IS NOT NULL condition
The IS NOT NULL condition is used in SQL to check a value other than NULL. It returns TRUE if a non-zero value is found, otherwise it returns FALSE
Published ย  July 5, 2020
๐ŸŒ
W3Schools
w3schools.com โ€บ mysql โ€บ mysql_notnull.asp
MySQL NOT NULL Constraint
The following SQL ensures that the "ID", "LastName", and "FirstName" columns will NOT accept NULL values when the "Persons" table is created: