0
我有一些產品的數據庫,他們可以用許多類別「標記」。有些產品沒有分配類別,我需要找到它們。需要查找沒有分類的記錄。我創造了這個表:在多對多關係中選擇沒有類別的記錄
ITEMS
+----+------+
| ID | Item |
+----+------+
| 1 | qwe |
| 2 | asw |
| 3 | wgr |
+----+------+
類別
+----+----------+
| ID | Category |
+----+----------+
| 1 | xxx |
| 2 | yyy |
+----+----------+
關係
+---------+--------+
| id_item | id_cat |
+---------+--------+
| 1 | 1 |
| 1 | 2 |
| 2 | 1 |
+---------+--------+
ŧ他是(不工作)查詢:
SELECT item.id COUNT(relationship.id_item) AS n
FROM item
JOIN relationships GROUP
BY relationships .n
WHERE item.id = relationships.id_item
AND relationships.n =0;