我需要有关此服务器内存不足的简单sql查询的帮助:
SELECT p.product_id, c.category_id
FROM product p, product_to_category ptc, category c
WHERE p.status = "1" AND
p.product_id = ptc.product_id AND
c.category_id = ptc.category_id
GROUP BY p.product_id;
怎么了我只想获取产品ID和产品的类别。
最佳答案
您不需要category
表。
SELECT p.product_id, ptc.category_id
FROM product p, product_to_category ptc
WHERE p.status="1"
AND p.product_id=ptc.product_id
并加入
SELECT p.product_id, ptc.category_id
FROM product p
JOIN product_to_category ptc
ON p.product_id=ptc.product_id
WHERE p.status="1"
关于mysql - 慢速mysql查询以获取产品ID及其类别ID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21260421/