我有三个表,产品、类别和 product_to_category。产品具有主键product_id、类别category_id和product_to_category p2c_id。Product_to_ category 使用它们各自的 ID 以多对多关系将产品链接到类别。
基本上我想编写一个查询,从类别表中不存在的类别中选择所有产品。这是由于产品从另一个数据库迁移而来。
我有这样的东西,但有点失落。
SELECT *
FROM product AS p
LEFT JOIN product_to_category AS p2c ON p.product_id = p2c.product_id
LEFT JOIN category AS c ON c.category_id
基本上这就是我所得到的。我需要将类别表加入到 product_to_category category_id 不在类别表中的 product_to_category 表中。我可能完全走错了路,但被卡住了!提前致谢。