2016-07-15 54 views
0

我得到的錯誤如下:如何識別在加入父別名(選擇

ER_BAD_FIELD_ERROR: Unknown column 'c.id' in 'where clause':

SELECT * 
FROM clients c 
LEFT JOIN 
    (SELECT GROUP_CONCAT(smpp_user), client_id 
    FROM client_accounts 
    WHERE client_id = c.id) AS l ON 
    l.client_id = c.id 

我需要從主SELECT用WHERE組smpp_user列各c.id

請幫助?我相信這是可能的。

回答

2

只需在您的子查詢中刪除WHERE子句並使用GROUP BY

SELECT * 
FROM clients c 
LEFT JOIN (
    SELECT GROUP_CONCAT(smpp_user), client_id 
    FROM client_accounts 
    GROUP BY client_id 
) AS l ON l.client_id = c.id 
+0

Thx,它的工作 – axon