下面的MYSQL語句按預期工作,列出簡歷在簡歷中使用的實例數。MYSQL查詢結果中重複列的問題
但是,它會返回兩次profile_id列。在第二個實例中,任何簡歷中都沒有使用配置文件,即使有值,profile_id也顯示爲NULL。
我相信我可能需要添加DISTINCT到查詢,但是我嘗試過的地方沒有奏效。
任何建議將不勝感激。
SELECT *, COALESCE(pc.postcount, 0) AS postcount
FROM profiles
LEFT JOIN (SELECT resumes.profile_id, COUNT(resumes.resume_id) AS postcount
FROM resumes
WHERE 1
GROUP BY resumes.profile_id) pc
ON pc.profile_id=profiles.profile_id
WHERE profiles.user_id = ?
謝謝!只需更改爲選擇profiles.profile_id,profiles.name,...做到了 – jsuissa 2012-02-06 22:35:42