1

我是 mysql 新手,我一直遇到这个查询的问题。

考虑这个查询:

SELECT a.group_message_id, a.scheduled_date, b.message, c.phone_number, d.group_name
    FROM schedule AS a
    JOIN group_message AS b ON a.group_message_id = b.id,
    JOIN phonenumber AS c ON c.id = a.phonenumber_id,
    JOIN group_table AS d ON d.group_id = a.group_id
    WHERE a.status = 'unsent'

而这个错误信息:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 4 行的“JOIN phonenumber AS c ON c.id = a.phonenumber_id, JOIN group_table AS d”附近使用正确的语法

我需要有关该声明实际错误的帮助。另外,如果您能向我展示其他“正确”的做法,我将不胜感激。

最后,如果没有足够的时间,是否有一个有效的资源可以让我至少从 mysql 的基础知识中学习。请分享。

4

2 回答 2

5

删除连接语句上的逗号,

JOIN group_message AS b ON a.group_message_id = b.id, -- <<== HERE
JOIN phonenumber AS c ON c.id = a.phonenumber_id,     -- <<== HERE
JOIN group_table AS d ON d.group_id = a.group_id

最终查询,

SELECT  a.group_message_id, 
        a.scheduled_date, 
        b.message, 
        c.phone_number, 
        d.group_name
FROM    schedule AS a
        JOIN group_message AS b 
            ON a.group_message_id = b.id
        JOIN phonenumber AS c 
            ON c.id = a.phonenumber_id
        JOIN group_table AS d 
            ON d.group_id = a.group_id
WHERE   a.status = 'unsent'
于 2013-01-22T12:00:45.763 回答
1

你不应该把逗号

只需检查这里的语法

示例语法

SELECT  column_list FROM  table1 JOIN table2 ON condition JOIN table3 ON condition WHERE condition
于 2013-01-22T12:11:33.443 回答