The Find Candidates for Data Scientist Position coding problem is a SQL-based filtering task. You are given a table Candidates that contains candidate IDs and their skills. Your goal is to identify all candidates who possess all three required skills for a Data Scientist role: 'Python', 'Tableau', and 'PostgreSQL'. The output should be a list of candidate IDs, sorted in ascending order.
This "Easy" level question is a frequent flyer at HashedIn and other data-focused firms. it's a test of your foundational SQL interview pattern skills, specifically your ability to perform grouping and set-based filtering. It evaluations whether you can correctly use the GROUP BY clause in combination with HAVING to ensure that a specific count of distinct attributes is met for each group.
This problem follows the Relational Division or Group-By with Filtering pattern.
WHERE clause to filter the rows to only include the three required skills.candidate_id.HAVING clause to check if the count of unique skills for that candidate is exactly 3.Table Candidates:
| candidate_id | skill |
|---|---|
| 1 | Python |
| 1 | Tableau |
| 1 | PostgreSQL |
| 2 | Python |
| 3 | Python |
| 3 | Tableau |
OR without counting: Simply selecting candidates with 'Python' OR 'Tableau' OR 'PostgreSQL' will include people who only have one of them.HAVING clause: Trying to filter the count in the WHERE clause, which is not allowed for aggregate functions.DISTINCT: If the table allows duplicate (id, skill) pairs, a candidate might have 'Python' listed twice and still pass the count check unless you use COUNT(DISTINCT skill).Whenever you see a problem asking for "entities that satisfy ALL conditions," think about grouping by the entity and checking the count of satisfied conditions. This is a very common template for "all-match" queries.