SQL QuestSQL Interview Questions › Querying Basics

Multiple Conditions (AND / OR)

EasyFreeQuerying Basics

Find male passengers in first class (pclass = 1) OR female passengers in third class (pclass = 3). Show name, sex, pclass, age, and survived. Limit to 20 rows. Be careful with operator precedence!

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".

Schema

passengers

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

Expected output: First-class men and third-class women

Hint

Use parentheses to group conditions: WHERE (sex = 'male' AND pclass = 1) OR (sex = 'female' AND pclass = 3). Without parentheses, AND binds tighter than OR.

Concepts

SELECT WHERE AND OR

Practise the topic: SQL practice questions

Related questions

Your First QueryEasy · FreePick Your ColumnsEasy · FreeFilter with WHEREEasy · FreeComparison OperatorsEasy · FreeThe IN OperatorEasy · FreeSorting and LimitingEasy · 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