Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Distinct Companies Applied To

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Distinct Companies Applied To. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

FNZ's candidate reporting workflow needs an overview of application reach. Write a PostgreSQL query that reports how many distinct companies each candidate has applied to.

Requirements

  1. Return every candidate, including candidates with no matching report rows.
  2. Count each company at most once per candidate, even when duplicate application reports exist.
  3. Exclude reports whose company name is NULL from the distinct count.
  4. Sort by the count descending, then by candidate_id ascending to make ties deterministic.

Schema

candidates
ColumnTypeDescription
candidate_idPKINTUnique candidate identifier
candidate_nameVARCHAR(100)Candidate's full name
emailVARCHAR(255)Candidate email address
reports
ColumnTypeDescription
report_idPKINTUnique application report identifier
candidate_idINTCandidate associated with the report
company_nameVARCHAR(150)Company applied to, when known
Tablescandidatesreports
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results