Learn SQL/Beginner/Filtering Data/SQL Comparison Operators

SQL Comparison Operators

The six symbols WHERE conditions are built from.

What & Why

Every basic WHERE condition uses one of six comparison operators. The operator tells PostgreSQL exactly how to compare a row’s value with the value in your condition.

OperatorMeaning
=equal to
!= or <>not equal to
>greater than
<less than
>=greater than or equal to
<=less than or equal to

See How It Works

Start with these four rows from marketing.campaigns. The condition keeps campaigns whose channel is not google_ads.

idnamechannelspendstart_date
1Spring Launchgoogle_ads55000.002024-01-15
2Retention Webinaremail45000.002024-02-10
3Finance Retargetinglinkedin50000.002024-03-12
4Enterprise Searchgoogle_ads60000.002024-04-01
EXAMPLE QUERY
SELECT name FROM marketing.campaigns WHERE channel != 'google_ads';
RESULT — channel != 'google_ads'
name
Retention Webinar
Finance Retargeting

The two google_ads rows fail the not-equal comparison, so only email and linkedin campaigns remain.

Beginner business practice

Sign up free to try it on a real business scenario