SQL
Lab
LinkedIn Easy Group By Having

Only One
Job
Listing

Find companies with exactly one job listing.

Table Schema

Inspect
Table

interactive
ColumnTypeDescription
job_idintegerUnique job posting identifier.
company_idintegerIdentifier for the company posting the job.
titlestringJob listing title.
departmentstringDepartment for the role.
locationstringJob location.
salaryintegerListed salary.
posted_datedateDate the job was posted.

Sample Data

Input
Output

Sample Input: job_listings
job_idcompany_idtitledepartmentlocationsalaryposted_date
11AnalystDataNY600002024-01-01
21EngineerEngNY900002024-01-02
32ScientistDataSF1200002024-01-03
42ManagerOpsSF1100002024-01-04
53AnalystDataTX700002024-01-05
64EngineerEngCA950002024-01-06
Expected Output
company_id
3
4

SQL Editor

Run
Query

postgresql
Waiting for query

company_id
3
4

Hints

Unlock
Clues

Hint 01: Group by company_id.
Hint 02: COUNT(*) tells you how many listings each company has.
Hint 03: HAVING COUNT(*) = 1 keeps companies with exactly one listing.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT
  company_id
FROM job_listings
GROUP BY company_id
HAVING COUNT(*) = 1;

Explanation

Step By
Step

01

Group rows by company_id.

02

Count how many listings are in each company group.

03

Keep groups with exactly one row.

Related Questions

Keep
Solving