SQL
Lab
LinkedIn Easy Anti Join Duplicates

No Duplicate
Job
Listings

Count companies with no duplicate job listings, where duplicates share the same company, title, and description.

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.
departmentstringDepartment for the role.
posted_datedateDate the job was posted.
employment_typestringType of employment.
Duplicate CheckReason
company_idDuplicates must be within the same company.
titleThe title must match exactly.
descriptionThe description must match exactly.

Sample Data

Input
Output

Sample Input: job_listings
job_idcompany_idtitledescriptiondepartmentposted_dateemployment_type
11AnalystWork on dataData2024-01-01Full-time
21AnalystWork on dataData2024-01-02Full-time
32EngineerBuild systemsEng2024-01-03Full-time
42AnalystAnalyzeData2024-01-04Contract
53ManagerLead teamHR2024-01-05Full-time
63ManagerLead teamHR2024-01-06Full-time
Expected Output
unique_companies
1

SQL Editor

Run
Query

postgresql
Waiting for query

unique_companies
1

Hints

Unlock
Clues

Hint 01: First find companies that have duplicate listing groups.
Hint 02: A duplicate group uses GROUP BY company_id, title, description and HAVING COUNT(*) > 1.
Hint 03: Count companies from job_listings whose company_id is not in the duplicate-company list.

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.

WITH duplicate_companies AS (
  SELECT
    company_id
  FROM job_listings
  GROUP BY company_id, title, description
  HAVING COUNT(*) > 1
)
SELECT
  COUNT(DISTINCT company_id) AS unique_companies
FROM job_listings
WHERE company_id NOT IN (
  SELECT company_id
  FROM duplicate_companies
);

Explanation

Step By
Step

01

Group rows by company_id, title, and description to identify duplicate listing groups.

02

Use HAVING COUNT(*) > 1 to find companies that should be excluded.

03

Count distinct company_id values from job_listings after removing companies found in the duplicate list.

Related Questions

Keep
Solving