Before you start, you need
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.
SELECT columns
FROM table_name
WHERE column_name <= value;See it in action
Which employees earn 30000 or more, including that amount?
SELECT name, salary
FROM employees
WHERE salary >= 30000;| name | salary |
|---|---|
| Claire Smith | 52000 |
| Alex Reed | 33000 |
| Charles Page | 46000 |
| Diana Lane | 39000 |
| Graham Newton | 31500 |
| Helen Cooper | 30000 |
| Isaac Davis | 36000 |
- Each salary is compared with 30000. >= accepts both the exact value and larger ones.
- 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.
- 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
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.
Below 30000 excludes anyone who earns exactly that figure.
Use WHERE on salary.
«Below» is written with <.
Solution explained
SELECT name, salary FROM employees WHERE salary < 30000;The condition excludes exactly 30000 and keeps the smaller values.
Your turn
Solve this variation. Spot the part that has changed before you look for help.
Practice
Include the limit
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.
Find a row that sits exactly on the limit.
You need a comparison that also allows equality.
The limit is written <= 30000.
Solution explained
SELECT name, salary FROM employees WHERE salary <= 30000;Helen Cooper appears because the 30000 boundary is included. Changing <= to < would leave her out.
Key takeaways
- > and < exclude the limit.
- >= and <= include the limit.
- = looks for equality; <> looks for inequality.