Module 2 · Filtering data

Compare values in your filters

By the end you will be able to choose a comparison that includes or excludes the limit.

About 10 min

0 of 52 lessons

Before you start, you need

Filter rows with WHERE

Decide whether the limit is included

«More than 30,000» and «at least 30,000» do not ask for the same thing. In the first case, someone who earns exactly 30,000 is left out. In the second, they are included. The limit in the question decides the operator.

> means greater than and < means less than. If the limit itself is also allowed, use >= or <=. For example, salary >= 30000 keeps both 30,000 and higher salaries.

= looks for an equal value; <> looks for a different one. You can compare quantities, such as a salary, or text in quotes, such as status = 'shipped'.

Always check a value below, one equal to and one above the limit. Helen Cooper earns exactly 30,000, which helps you tell apart > of >=. Write the symbols in that order: => is not a SQL comparison.

Minimal syntax
SELECT columns
FROM table_name
WHERE column_name <= value;

See it in action

Which employees earn 30000 or more, including that amount?

SQL
SELECT name, salary
FROM employees
WHERE salary >= 30000;
Example result: 7 rows
namesalary
Claire Smith52000
Alex Reed33000
Charles Page46000
Diana Lane39000
Graham Newton31500
Helen Cooper30000
Isaac Davis36000
  1. Each salary is compared with 30000. >= accepts both the exact value and larger ones.
  2. Helen Cooper earns exactly 30000 and appears. With > she would be left out, even if the rest of the result were identical: that is why it is worth checking the boundary row.
  3. The row that sits on the limit lets you check whether the operator expresses the question correctly. Write >= in that order, not =>.

Practice with help

Getting things wrong is part of learning: you can run your query as many times as you like and nothing is lost. If you get stuck, open a hint (each one reveals a bit more) and save the solution for last.

Guided practice

Find salaries below the limit

Not started

Write a query that returns name and salary for employees with a salary below 30000.

Expected result: 3 rows with the columns name, salary, in that order. Row order does not matter.

View tables and data

Open this panel to see the full data.

Your turn

Solve this variation. Spot the part that has changed before you look for help.

Practice

Include the limit

Not started

Show name and salary for employees who earn up to 30000, inclusive.

Expected result: 4 rows with the columns name, salary, in that order. Row order does not matter.

View tables and data

Open this panel to see the full data.

Key takeaways

  • > and < exclude the limit.
  • >= and <= include the limit.
  • = looks for equality; <> looks for inequality.

Next: Combine conditions with AND, OR and NOT