This will give you every pair of authors twice: if John and Joe co-write a paper, there will be entries for
CoAuthor1 CoAuthor2 JointPapers
JOHN JOE 1
JOE JOHN 1
The code is:
SELECT
a1.firstName AS CoAuthor1,
a2.firstName AS CoAuthor2,
l.JointPapers
FROM
(
SELECT
pba1.authorID AS CoAuthorID1,
pba2.authorID AS CoAuthorID2,
COUNT(*) AS JointPapers
FROM
PaperByAuthor AS pba1
LEFT JOIN
PaperByAuthor AS pba2
ON
pba1.paperID = pba2.paperID
GROUP BY
pba1.authorID,
pba2.authorID
) AS l
LEFT JOIN
Authors AS a1
ON
l.CoAuthorID1 = a1.authorID
LEFT JOIN
Authors AS a2
ON
l.CoAuthorID2 = a2.authorID