More operators for WHERE clauses

In the last lesson, we used WHERE clauses to look for specific values with the "equals" operator, =.

You can also use WHERE clauses to exclude specific values, with the "not equal" operator, !=.

SELECT name, contactNumber FROM owners
WHERE city != 'Cambridge'

Here are four more operators:

  • >Greater than: find rows where the left-hand value is greater than (but not equal to) the right-hand value
  • >=Greater than or equal to: the left-hand value is greater than or equal to the right-hand value
  • <Less than: the left-hand value is less than (but not equal to) the right-hand value
  • <=Less than or equal to: find rows where the left-hand value is less than or equal to the right-hand value

Here's an example:

SELECT licensePlate, mileage FROM cars
WHERE mileage > 10000

Task

What your results should look like

Query

Result

There was an error in your SQL query: {{error}}

{{executedQuery}}

Correct answer. Bonza!

Congratulations! You've completed all of the tasks in this lesson.

Next lesson: Combining WHERE clauses

Wrong answer. Have another a go.

Hint: {{hint}}

Next lesson: Combining WHERE clauses

Once you think you've nailed this lesson, feel free to go to the next lesson.

Next lesson

Questions? Suggestions?

We'd love to hear any feedback you have for us. Just send an email to hello@learnsomesql.com.