SELECT DISTINCT b.b_id
FROM b INNER JOIN c
ON b.b_id=c.b_id
WHERE c.active='yes' AND b.featured='no'
當結果應該是0行返回,將返回一個空一行數= 0
SELECT DISTINCT b.b_id, COUNT(c.c_id) AS count
FROM b INNER JOIN c
ON b.b_id=c.b_id
WHERE c.active='yes' AND b.featured='no'
難道我做錯了什麼?
當您使用聚合函數('COUNT')時,您需要將'GROUP BY'作爲非聚合列。 MySQL甚至不應該允許該查詢,但它會導致不可預知的行爲... – bernie
ahh,好吧,所以我已經在查詢結束時通過b.b_id刪除了DISTINCT和附加GROUP。是對的嗎? – lewicki