PostgreSQL – IS NOT NULL

IS NOT NULL condition is used in the WHERE clause to identify records that have a value for the specified condition.(records that are not null)

Syntax:

SELECT * FROM table_name WHERE column_name IS NOT NULL;

Consider an employee table as shown below:

idfirst_namelast_namedepartmentsalaryemail
101bryanwalkersales50,000bryan.walker@email.com
102alexcarpenteraccounts55,000alex.carpenter@email.com
103samwhitesales60,000sam.white@egmail.com
104johnbarrysales54,000john.barry@email.com
105billwoodaccounts65,000
106roberthopkinssupport70,000
107davidleesupport72,000david.lee@email.com
108jacksearssupport65,000
109tomyoungsales55,000tom.young@email.com

Below is the SQL query to return employees that provided an email address:

SELECT id, email FROM employee WHERE email IS NOT NULL;

id      email
--     -------
101 bryan.walker@email.com
102 alex.carpenter@email.com
103 sam.white@egmail.com
104 john.barry@email.com
107 david.lee@email.com
109 tom.young@email.com
See also  PostgreSQL - Count distinct over multiple columns