Comparison Operators
A comparison turns values into a condition
Comparison operators let you compare a column value with another value. Such expressions often form the basis of a WHERE condition.
=— equal to;<>— not equal to;>and<— greater than and less than;>=and<=— greater than or equal to and less than or equal to.
SELECT name, price
FROM products
WHERE price <= 500;
The query returns products priced at 500 or less. The boundary is included because <= is used instead of <.
Compare compatible values
The meaning of a comparison depends on the data type. Numbers are compared as numbers, dates as dates, and strings according to the rules and collation settings of the database system. So not only the operator matters, but also the types of the values on both sides.
The standard SQL operator for “not equal” is <>.
Some database systems also support
!=, but <> better represents portable SQL syntax.
Check yourself
Exercise review
The mentor knows the solution and will help you reach it independently
Sign in to use the Mentor
The Mentor uses the current exercise and your conversation history.
Sign in
Review the key nuances and the answer after making your own attempt.
Sign in to view the solution
The solution and explanation are available after signing in.
Sign in