如何使 MySQL 8 与包含多个 FROM 表的语句兼容
How to make MySQL 8 compatible with statements containing multiple FROM tables
我正在从 MySQL 5.7 迁移到 8.0,我的一个应用程序在现有 SQL 查询中抛出错误,如下所示:
SELECT
g.*,
gp.file_name AS group_picture_fn
FROM groups g,
group_picture gp
WHERE
g.status = 3
AND g.ID = gp.group_id
ORDER BY
timestamp desc LIMIT 4
错误:
[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups g, group_picture gp WHERE g.status = 3 AND g.ID = gp.group_i' at line 2
查询在旧系统上运行正常。我可以在 MySQL 配置/SQL 模式上更改任何内容以使其兼容,还是我必须用类似 JOIN 的语法重写查询?
关键字 GROUPS 已添加到版本 8.0.2
参见:https://dev.mysql.com/doc/refman/8.0/en/keywords.html
问题是您需要转义您的 table 名称和别名,这样它们就不会被视为关键字。
SELECT
`g`.*,
`gp`.`file_name` AS `group_picture_fn`
FROM `groups` `g`,
`group_picture` `gp`
WHERE
`g`.`status` = 3
AND `g`.`ID` = `gp`.`group_id`
ORDER BY
`timestamp` desc LIMIT 4
我正在从 MySQL 5.7 迁移到 8.0,我的一个应用程序在现有 SQL 查询中抛出错误,如下所示:
SELECT
g.*,
gp.file_name AS group_picture_fn
FROM groups g,
group_picture gp
WHERE
g.status = 3
AND g.ID = gp.group_id
ORDER BY
timestamp desc LIMIT 4
错误:
[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups g, group_picture gp WHERE g.status = 3 AND g.ID = gp.group_i' at line 2
查询在旧系统上运行正常。我可以在 MySQL 配置/SQL 模式上更改任何内容以使其兼容,还是我必须用类似 JOIN 的语法重写查询?
关键字 GROUPS 已添加到版本 8.0.2
参见:https://dev.mysql.com/doc/refman/8.0/en/keywords.html
问题是您需要转义您的 table 名称和别名,这样它们就不会被视为关键字。
SELECT
`g`.*,
`gp`.`file_name` AS `group_picture_fn`
FROM `groups` `g`,
`group_picture` `gp`
WHERE
`g`.`status` = 3
AND `g`.`ID` = `gp`.`group_id`
ORDER BY
`timestamp` desc LIMIT 4