So I am given the following table:
ResInt (pid, topic) - Person with pid has topic as a research interest
And I need to accomplish the following:
1. Write a SQL query to find all person-person-interest triplets (pid1,
pid2, topic) such that person pid1 has topic as a research interest,
but person pid2 doesn’t. Call this the PPT view.
2. Given the earlier view PPT and the original table ResInt,
write the full SQL query to find all pairs of people with the exact
same set ofresearch interests. Remove mirror pairs and self-pairs.
A person can have multiple interests so there may be multiple tuples of the same PID with different topics in the table.
My attempt looks something like this:
CREATE VIEW PPT AS
SELECT T1.pid AS FirstPID, SELECT T2.pid as SecondPID, T1.topic
FROM ResInt AS T1, ResInt AS T2
WHERE T1.pid != T2.pid AND T1.topic != T2.topic
But this would only give me different combinations of tuples in which two different people don't have the same interest listed. I think this would also add way too many tuples that don't belong, as each combination of differing topics would be added, rather than the people which don't have some interest in common.