-1

我试图合并两个具有另一个表(group_message_log)的外键的表。但发生错误。

错误:未知表 'group_message_log'

SELECT `message_id`,group_message_log.* FROM `messages_log` AS `log_1` JOIN `group_message_log` AS `gm` ON `message_id` = gm.id WHERE `student_id`='128' 
UNION ALL 
SELECT `message_id`,group_message_log.* FROM `message_phone_log` AS `log_2` JOIN `group_message_log` AS `gm` ON gm.id = `message_id` WHERE (`phone`='XXX' OR `phone`='XXX')
4

1 回答 1

1

您正在使用带有别名的表名, group_message_log AS gm 因此您应该使用gm全名的别名 insetad,group_message_log如下所示

SELECT `message_id`,gm.* FROM `messages_log` AS `log_1` JOIN `group_message_log` AS `gm` ON `message_id` = gm.id WHERE `student_id`='128' 
UNION ALL 
SELECT `message_id`,gm.* FROM `message_phone_log` AS `log_2` JOIN `group_message_log` AS `gm` ON gm.id = `message_id` WHERE (`phone`='XXX' OR `phone`='XXX')
于 2013-09-18T18:54:01.370 回答