Find candidates who have every required skill: Python, Tableau and PostgreSQL.
Updated ·1 min read
Question
Given a table of candidates and their skills, list the candidates qualified for an open Data Science role. A qualified candidate has all of these skills: Python, Tableau, and PostgreSQL. Sort the result by candidate_id in ascending order.
Assume there are no duplicate rows in the candidates table.
candidates table
Column
Type
candidate_id
integer
skill
varchar
Example input
candidate_id
skill
123
Python
123
Tableau
123
PostgreSQL
234
R
234
PowerBI
234
SQL Server
345
Python
345
Tableau
Expected output
candidate_id
123
Solution
SELECT candidate_idFROM candidatesWHERE skill IN ('Python', 'Tableau', 'PostgreSQL')GROUP BY candidate_idHAVING COUNT(DISTINCT skill) = 3ORDER BY candidate_id ASC;
What this demonstrates
WHERE filters eligible skill rows before GROUP BY.
COUNT(DISTINCT skill) counts how many required skills each candidate has.
HAVING keeps only candidates whose distinct required-skill count is three.