加入3个表时出错1066

时间:2014-06-14 07:49:04

标签: mysql sql select join inner-join

现在有以下问题。我试图使用以下查询从3个表中获取数据。

SELECT Message, Name
FROM message, users
LEFT JOIN user_message ON ID = Message_id
LEFT JOIN user_message ON ID = User_id
WHERE user_message.status = 1
LIMIT 0 , 30

在这里我收到错误1066我错过了什么?

2 个答案:

答案 0 :(得分:1)

试试这个:

SELECT m.Message, u.Name
FROM message m
INNER JOIN user_message um ON m.ID = um.Message_id
INNER JOIN users u ON u.ID = um.User_id
WHERE um.status = 1
LIMIT 0, 30;

答案 1 :(得分:0)

您需要提供别名并尝试这样

SELECT t1.Message, t2.Name
FROM message as t1
LEFT JOIN user_message as t2 ON t2.ID = t1.Message_id 
LEFT JOIN users as t3. ON t3.ID = t2.User_id
WHERE t3.status = 1
LIMIT 0 , 30