AnalystPath

Collaborator Pairs With No Shared Collaborator

SQLMediumMid level~15 min

Problem

Table `Collabs` records direct collaborations between researchers as undirected pairs: each row holds two researcher ids `person_a` and `person_b` who have worked together. A collaboration goes both ways, so if `person_a` worked with `person_b`, then `person_b` also worked with `person_a`.

Find every collaboration pair such that the two researchers share no common collaborator -- that is, there is no third researcher who has worked with both members of the pair.

Return `person_a` and `person_b` for each such pair, ordered by `person_a` then `person_b`.

Tables

Example rows — the live problem includes the full dataset.

Collabs
person_aperson_b
12
23
24

Expected output

Your answer should return 2 rows with the columns person_a, person_b.

Starter code (SQL)

SELECT *
FROM Collabs;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions