SQL Quest › SQL Interview Questions › Querying Basics

Working-Age Passengers (BETWEEN)

EasyFreeQuerying Basics

An insurance analyst is profiling passengers who would have been in the workforce age range at the time of the voyage. Use the BETWEEN operator to find passengers aged 18 to 65 inclusive.

Show name, sex, age. Order by age ascending, then name ascending.

age BETWEEN 18 AND 65 is equivalent to age >= 18 AND age <= 65 but reads more clearly when you mean an inclusive range — and it's the form interviewers expect when the prompt says "between".

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect". Free accounts get 10 free challenge solves, and this can be one of them.

Schema

passengers

passenger_idsurvivedpclassnamesexagesibspparchfareembarked
103Braund, Mr. Owen Harrismale22107.25S
211Cumings, Mrs. John Bradleyfemale381071.28C
313Heikkinen, Miss. Lainafemale26007.93S

Expected output: Only the 22-year-old and 45-year-old appear

Hint

WHERE age BETWEEN 18 AND 65. Both endpoints are inclusive. NULL ages are excluded automatically because comparisons with NULL return UNKNOWN, not TRUE.

Concepts

SELECT WHERE BETWEEN ORDER BY

Practise the topic: SQL practice questions

Read the concept: SQL tutorial

Related questions

DISTINCT ValuesEasy · FreePattern Matching with LIKEEasy · FreeRecent Hit Movies (2010s)Easy · FreeNon-Sales Roster (NOT IN)Easy · FreeDepartment Leaderboard (Multi-Key Sort)Easy · FreePassengers Without Mr. or Mrs. (NOT LIKE)Easy · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test