SQL: Select null value

If we have a table with null value, the row can be filtered out using is null or is not null.

CREATE TABLE artist
	(
 id int auto_increment primary key, 
 artiste varchar(30), 
 album varchar(50),
 year int(10)
 );

INSERT INTO artist
(artiste, album, year)
VALUES
(null, 'Maggie May', 1973),
('New Order', 'Substance', 1987),
('Nirvana', 'Smell Like Teen Spirit', 1992);

SQL Fiddle

The query statement is:

select * from artist where artiste is null

SQL Fiddle

select * from artist where artiste is not null

SQL Fiddle

Note that you can’t use comparison operator (such as = or <>) to check for null.  This is a common mistake.

For example, the query below will return 0 record.

select * from artist where artiste is = null

SQL Fiddle

Series Navigation<< SQL: NULL value
SQL: Functions >>