MySQL:联合查询在 MySQL 5.5 上失败,在 MySQL 5.1 上工作
我在处理顽固的 MySQL 查询时遇到了麻烦。这是一个相当长且复杂的查询,对此感到抱歉。我真的尽了最大努力自己找到它,但我可以在这里求助。
以下查询用于模拟 information_schema 中的列信息和名为 nexedit_schema 的表中的列信息的完全外连接。 PHP 变量 $db 包含包含后一个表的目标数据库。
该查询实际上在我自己的服务器(MySQL 版本 5.1)上成功运行,但在朋友的服务器(MySQL 版本 5.5)上运行失败。它声称我在“ON (schema_tables.db_table...”附近有一个语法错误,
我可能忽略了一些非常愚蠢的事情。任何好心人可以帮助我吗?
SELECT information_schema.tables.table_name, schema_tables.db_table, schema_tables.ne_page
FROM information_schema.tables
LEFT JOIN (
(SELECT DISTINCT db_table, ne_page FROM {$db}.nexedit_schema)
AS schema_tables)
ON (schema_tables.db_table = information_schema.tables.table_name
COLLATE utf8_unicode_ci)
WHERE information_schema.tables.table_schema = '{$db}'
AND information_schema.tables.table_name NOT LIKE 'nexedit_%'
UNION
SELECT information_schema.tables.table_name, schema_tables.db_table, schema_tables.ne_page
FROM information_schema.tables
RIGHT JOIN (
(SELECT DISTINCT db_table, ne_page FROM {$db}.nexedit_schema)
AS schema_tables)
ON (schema_tables.db_table = information_schema.tables.table_name
COLLATE utf8_unicode_ci)
WHERE information_schema.tables.table_schema IS NULL
AND schema_tables.db_table NOT LIKE 'nexedit_%'
GROUP BY information_schema.tables.table_name,schema_tables.db_table;
I'm having trouble with a stubborn MySQL query. It's a quite long and complex query, sorry about that. I really did my best to find it myself but I could use a hand here.
The following query is used to emulate a full outer join of column information in the information_schema, and column information in a table called nexedit_schema. The PHP variable $db contains the target database that contains the latter table.
The query actually successfully runs on my own server (MySQL version 5.1), but fails to run on a friend's server (MySQL version 5.5). It claims that I have a syntax error near "ON (schema_tables.db_table..."
I'm probably overlooking something really stupid. Anyone kind enough to help me out?
SELECT information_schema.tables.table_name, schema_tables.db_table, schema_tables.ne_page
FROM information_schema.tables
LEFT JOIN (
(SELECT DISTINCT db_table, ne_page FROM {$db}.nexedit_schema)
AS schema_tables)
ON (schema_tables.db_table = information_schema.tables.table_name
COLLATE utf8_unicode_ci)
WHERE information_schema.tables.table_schema = '{$db}'
AND information_schema.tables.table_name NOT LIKE 'nexedit_%'
UNION
SELECT information_schema.tables.table_name, schema_tables.db_table, schema_tables.ne_page
FROM information_schema.tables
RIGHT JOIN (
(SELECT DISTINCT db_table, ne_page FROM {$db}.nexedit_schema)
AS schema_tables)
ON (schema_tables.db_table = information_schema.tables.table_name
COLLATE utf8_unicode_ci)
WHERE information_schema.tables.table_schema IS NULL
AND schema_tables.db_table NOT LIKE 'nexedit_%'
GROUP BY information_schema.tables.table_name,schema_tables.db_table;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有不必要的
)
:AS schema_tables)
应该在AS
之前There's unnecessary
)
here:AS schema_tables)
Should be beforeAS