I’m taking a database course and I’ve got stuck on one of the questions. “For all cases where A is friends with B, and B is friends with C, add a new friendship for the pair A and C”.
This is as far as I’ve got
INSERT INTO
friend
SELECT DISTINCT
f1.ID1, f2.ID1
FROM
friend f1
JOIN friend f2 using (ID2),
friend
WHERE
f1.ID1 <> f2.ID1
AND friend.ID1 <> f1.ID1
AND friend.ID2 <> f1.ID2
The schema is here http://www.sqlfiddle.com/#!5/cf8b5/23
I wonder if somebody could give me a few hints on how to proceed.
Thanks.
I think you have the basic concepts.
I’d do it like the following: