Reputation: 11
Say I have the following table:
+------------+------+--------+
| reviewerID | item | rating |
+------------+------+--------+
| 1 | 1 | 5|
| 1 | 2 | 5|
| 1 | 3 | 5|
| 2 | 4 | 5|
| 2 | 1 | 5|
| 2 | 2 | 5|
+------------+------+--------+
And I want to get the items not rated by reviewer 1 but rated by reviewer 2 and vice versa into one table. The output should be something like this:
+------------+------+--------+
| reviewerID | item | rating |
+------------+------+--------+
| 1 | 3 | 5|
| 2 | 4 | 5|
+------------+------+--------+
Upvotes: 1
Views: 83
Reputation: 77
Here's what you need, to get the desired results....
SELECT a.* FROM Reviewer a
JOIN ( SELECT DISTINCT item FROM Reviewer
GROUP BY item
HAVING count(item) < 2) b
ON a.item = b.item
Hope it helps!! Good luck!!
Upvotes: 0
Reputation: 311228
You could count the number of reviewers the items had (between those two reviewers) and only select those with one reviewer:
SELECT *
FROM mytable
WHERE item IN (SELECT item
FROM mytable
WHERE reviewerID IN (1, 2)
GROUP BY item
HAVING COUNT(*) = 1)
Upvotes: 1