WHERE Clause & Filtering SQL Topic exerciseMediumVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

Review Candidates at Inclusive Salary Boundaries

Find candidates earning from $60,000 through $75,000.

  • Filtering
  • Sorting

Exercise brief

Understand the request

Candidate compensation analyst A salary-band review must retain candidates at both approved endpoints.

Return candidates earning from $60,000 through $75,000, including both endpoints.

Return

  • Return candidate_id, team_code, salary in this exact left-to-right order.

Constraints

  • Treat both $60,000 and $75,000 as inclusive boundaries.

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

cohort_candidates

  • candidate_idINTEGER
  • team_codeTEXT
  • salaryDECIMAL

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

An inclusive range keeps rows at both the lower and upper salary boundaries.

Hint 2

Use BETWEEN with the lower value first, then make ordering deterministic for candidates who share a salary.

Hint 3

SELECT candidate_id, team_code, salary FROM cohort_candidates WHERE salary BETWEEN /* inclusive lower */ AND /* inclusive upper */ ORDER BY salary, /* tie breaker */;

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT candidate_id, team_code, salary FROM cohort_candidates WHERE salary BETWEEN 60000 AND 75000 ORDER BY salary, candidate_id;

Why this works

BETWEEN is equivalent to `salary >= 60000 AND salary <= 75000`, so the fixture's exact $60,000 and $75,000 rows must be present. Using strict comparisons drops those boundary candidates, while reversing the endpoints returns no rows. Numeric BETWEEN is inclusive across all supported engines; the second sort key makes equal salaries deterministic.

Success check

Every salary is inside the inclusive band and equal salaries have deterministic ordering.

Expected result

Use this output to verify values, aliases, ordering, and row count.

candidate_idteam_codesalary
101DATA60000
109DATA60000
102PLATFORM60001
113DATA68000
114SALES69000
103IT70000
104SALES70001
105IT72000
111SECURITY74000
106HR75000

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.