我有几个表我试图有效地获取数据。
我有一个这样的草拟查询:
SELECT products.id, products.name products.extended_description, products.catalogid, products.image1, products.image2, products.stock, products.price, manufacturer.manufacturer, products.weight
FROM products
JOIN manufacturer ON (products.manufacturer = manufacturer.id)
WHERE category.category_name = ?;
显然这是一个损坏的查询,但我不知道如何解决这个问题。我需要以某种方式将category
表连接到通过字段与表product_category
相关的表。products
products.catalogid
我的微弱尝试是这样的:
SELECT products.id, products.name products.extended_description, products.catalogid, products.image1, products.image2, products.stock, products.price, manufacturer.manufacturer, products.weight
FROM products
JOIN manufacturer ON (products.manufacturer = manufacturer.id)
FROM category
JOIN product_category ON (category.id = (SELECT product_category.id FROM product_category WHERE product_category.catalogid /*I'm so lost...*/))
WHERE category.category_name = ?;
基本上我需要查询 db 以获取 SELECT 子句中类别名称为“NEW”的所有信息......我完全被难住了(我的 SQL 显然需要一些工作!)