Join relation on itself and pull distinct rows
SELECT t1.reviewer_id AS first, 
       t2.reviewer_id AS second, 
       t1.book_id
FROM table AS t1 
LEFT JOIN table AS t2 ON t2.book_id = t1.book_id 
                     AND t2.reviewer_id &gt; t1.reviewer_id


or

SELECT MIN(reviewer_id) AS first, 
       CASE WHEN COUNT(reviewer_id) &gt; 1 
            THEN MAX(reviewer_id) 
            ELSE NULL
            END AS second, 
       book_id
FROM table
GROUP BY book_id