2017-04-23 70 views
0

MySQL查詢:未知列 '的條款' 在 'user.id'

SELECT 
    *, 
    `message`.`status` as `message_status`, 
    `message`.`id` as `message_id`, 
    group_concat(response.response) as response, 
    group_concat(response.id) as response_id, 
    `message`.`user_id` as `sender` 
FROM `message` 
LEFT JOIN `pet_info` ON `pet_info`.`id` = `message`.`pet_id` 
LEFT JOIN `response` ON `response`.`message_id` = `message`.`id` 
LEFT JOIN `user` as sender ON `user`.`id` = `message`.`user_id` 
LEFT JOIN `user` as receiver ON `user`.`id` = `message`.`owner_id` 
WHERE `user_id` = '6' 
AND `pet_id` = '6' 
GROUP BY `message`.`id` 

我怎樣才能解決這個問題?

回答

0

你走樣表:

LEFT JOIN `user` as sender 

這意味着,只要查詢的其它部分而言,沒有user表。有一個sender表。因此,您需要使用ON子句中的別名:

LEFT JOIN `user` as sender ON `sender`.`id` = `message`.`user_id` 
相關問題