Lets say we have the table SP(sid, pid) which shows student sid is involved in project pid.
Now I want a mysql query to select all the pairs of students who involved at least in one project, and the number of projects that they collaborate in.
For example:
input:
S1 P1
S1 P2
S2 P1
S3 P1
S4 P1
S4 P2
Output:
S1 S2 1
S1 S3 1
S1 S4 2
S2 S3 1
S2 S4 1
S3 S4 1
Eric’s answer might be a bit improved:
Use < instead of <> to avoid geting (1,4,2) AND (4,1,2)