SQL
Lab
LinkedIn Easy Group By Duplicates

Cross Company
Duplicate
Listings

Find job listings with identical title and description across different companies.

Table Schema

Inspect
Table

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

Sample Data

Input
Output

Sample Input: job_listings
job_idcompany_idtitledescriptionlocationsalaryposted_date
11AnalystWork on dataNY600002024-01-01
22AnalystWork on dataSF700002024-01-02
33EngineerBuild systemsTX900002024-01-03
44EngineerBuild systemsCA950002024-01-04
55ManagerLead teamNY1000002024-01-05
66AnalystAnalyze reportsTX650002024-01-06
Expected Output
titledescription
AnalystWork on data
EngineerBuild systems

SQL Editor

Run
Query

postgresql
Waiting for query

titledescription
AnalystWork on data
EngineerBuild systems

Hints

Unlock
Clues

Hint 01: The duplicate definition ignores company_id, but companies must be different.
Hint 02: Group by title and description.
Hint 03: Use HAVING COUNT(DISTINCT company_id) > 1.

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
  title,
  description
FROM job_listings
GROUP BY title, description
HAVING COUNT(DISTINCT company_id) > 1;

Explanation

Step By
Step

01

Group rows by the listing fields that must match: title and description.

02

Count distinct company IDs inside each group.

03

Keep groups that appear under more than one company.

Related Questions

Keep
Solving