我有幾個表我「米試圖讓數據出有效加入在查詢的WHERE子句
我有一個草擬的查詢這樣:
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.catalogid
領域涉及products
表
我愚蠢的嘗試是這樣的:。
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 = ?;
基本上我需要查詢數據庫的SELECT子句where類別名稱爲「NEW」中的所有信息...,我徹底難倒了(我的SQL顯然需要一些工作!)
不能有muliple'from'的,而不是從某種加入 –
我只是說類似的更換第二: '(加入製造商ON(products.manufacturer = manufacturer.id))(類別JOIN product_category ON ... ... ...)'? – SnakeDoc
只需加入:'在product_category.product = products.id上加入product_category在product_category.Category = category.id'上加入類別。 –