I am getting 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
Based on your comment, the correlation can’t be placed within the
JOINof the correlated sub-query.It can, however, be placed in the
WHEREclause of the correlated sub-query.That answers your explicit question; why your query failed syntactically.
I would, however, replace the whole correlation with a simple
LEFT JOIN.