Comparison Operators in WHERE (PostgreSQL)
We’ve already seen that the WHERE keyword allows us to filter rows returned by a query. In simple words: WHERE checks each row one by one and decides whether it should
We’ve already seen that the WHERE keyword allows us to filter rows returned by a query.
In simple words:
WHERE checks each row one by one and decides whether it should appear in the final result.Let’s now look at different comparison operators we can use inside a WHERE clause.
Recap: Filtering with WHERE
Consider this query:
select
name,
area
from cities
where area > 4000;
What happens here is very simple:
- PostgreSQL looks at each row
- It checks the
areavalue - Only rows with
area > 4000are returned
That’s why we only see cities like Tokyo and Shanghai.
Equality Check (=)
We can also check if a column value is exactly equal to something.
For example, let’s find the city with an area equal to 8223:
select
name,
area
from cities
where area = 8223;
Important Note
In SQL:
=is not assignment- it is a comparison operator
We are not changing anything — we are just checking a condition.
Result
This query returns:
- Tokyo
Because Tokyo is the only city with an area of 8223.
Not Equal (!=)
We can also check for values that are not equal.
select
name,
area
from cities
where area != 8223;
This returns:

