請看看下面的查詢 - 我得到Unknown column 'u.id' in 'on clause'
表別名範圍的子選擇查詢
SELECT id, username,
coalesce(
(SELECT name from company c
INNER JOIN user_company uc
ON uc.user_id = u.id
AND c.id = uc.company_id), 'NOT-AVAILABLE'
) companyname
FROM `user` u
用戶表是否實際上有一個列ID? –
是的它確實有.... – user1421214
嘗試將子查詢更改爲:從公司c選擇姓名 INNER JOIN user_company uc ON c.id = uc.company_id WHERE uc.user_id = u.id –