MySQL查询:
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 :(得分:0)
你正在对表格进行别名处理:
LEFT JOIN `user` as sender
这意味着,就查询的其余部分而言,没有user
表。有一个sender
表。所以你需要在ON
子句中使用别名:
LEFT JOIN `user` as sender ON `sender`.`id` = `message`.`user_id`