![](/img/trans.png)
[英]Select name, lastname, brand from table where brand is the most voted
[英]SQL to select brand from a table, if another table has a product with that brand
使用MySQL和PHP。
我有兩個表產品和庫存。
產品具有{productID | 產品| 品牌|}
庫存有{ID | storeID | productID | 數量 價錢 }
我需要在特定商店獲得所有品牌。
所以這是我無法使用的。
SELECT DISTINCT brand
FROM products
WHERE 'products.productID' = 'stock.productID'
AND 'stock.storeID' = 1
如果刪除比較“ WHERE”,它將返回所有品牌。
嘗試
Select p.brand FROM products p, stock s
WHERE p.productID=s.productID and s.storeID='1'
SELECT DISTINCT p.brand
FROM products p inner join stock s on p.productID=s.productID
WHERE `stock.storeID` = 1
標記`和'之間的差異
嘗試
"SELECT p.* FROM Products p
INNER JOIN stock s USING(productID)
WHERE s.storeID = '".(int)$givenID."'
GROUP BY p.brand";
我們也可以這樣寫
SELECT DISTINCT p.brand FROM products p , stock s where p.productID=s.productID(+) and stock.storeID = 1
嘗試這個:
SELECT DISTINCT p.brand
FROM products p
INNER JOIN stock s
ON p.productID=s.productID
WHERE s.`storeID` = 1
這會有所幫助
select p.brand
from product p, stock s
where p.productID = s.productID
and s.storeID = 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.