Collaborator Pairs With No Shared Collaborator
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.
| person_a | person_b |
|---|---|
| 1 | 2 |
| 2 | 3 |
| 2 | 4 |
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