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.
| Operator | Meaning |
|---|---|
= | 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.
| id | name | channel | spend | start_date |
|---|---|---|---|---|
| 1 | Spring Launch | google_ads | 55000.00 | 2024-01-15 |
| 2 | Retention Webinar | 45000.00 | 2024-02-10 | |
| 3 | Finance Retargeting | 50000.00 | 2024-03-12 | |
| 4 | Enterprise Search | google_ads | 60000.00 | 2024-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.
Now You Try
Practice this concept
Marketing wants low-score leads that need cleanup. Return leads with lead score below 40.
Available schema
marketingPrefix tables with marketing.table_name.
idsourcelead_scoremarketing.leads| Column | Type |
|---|---|
| id | integer |
| campaign_id | integer |
| text | |
| created_at | timestamp with time zone |
| qualified_at | timestamp with time zone |
| converted_at | timestamp with time zone |
| lead_score | integer |
| source | text |
| country | text |
| archive_status | text |
query.sql
Sign up free to try it on a real business scenario