UNION SELECT CONCAT 在 MariaDB / MySQL 之间的工作方式不同
UNION SELECT CONCAT works differently between MariaDB / MySQL
我最近将一个应用程序从 MySQL 5.5 迁移到了 MariaDB 10.3。
该应用程序的一部分是一个事件日历,用户可以在其中输入自己的事件,其中包含地址、城镇等详细信息。
我注意到其中一个查询 运行 这个软件不再与 MariaDB 一起工作,尽管语法应该还不错。
我已尝试返回 MySQL 5.5,查询再次运行。
我还在 MariaDB 10.3 上的 phpMyadmin 中进行了查询 运行,它显示了相同的结果,但以错误结尾:
ERROR 1064: You have an error in your SQL syntax; check the manual for
the right syntax to use near 'UNION SELECT CONCAT(title_clang_1,' -
',street,' ',zip,' ',district,' ', town,' in line 1
这是查询:
SELECT
'choose' label,
'' id
FROM
table_events
LIMIT
1
UNION
SELECT
CONCAT(
title_clang_1,
' - ',
street,
' ',
zip,
' ',
district,
' ',
town,
' ',
additional
) label,
id
FROM
table_events
WHERE
offline IS NULL || offline = '|0|'
table "table_events" 包含此处列出的所有列:id、title_clang_1、street、zip、district、town、additional - 以及与此查询无关的更多列.
我希望输出所有离线字段填充零或 NULL 的事件,但我收到语法错误。
我很确定你的这个查询在 MySQL 中也不起作用(至少在较新的版本中)。 MySQL Documentation 明确指出:
To apply ORDER BY or LIMIT to an individual SELECT, place the clause
inside the parentheses that enclose the SELECT
您需要在您的个人 SELECT
查询块周围使用括号,因为您在第一个查询中使用 LIMIT
:
(
SELECT
'choose' label,
'' id
FROM
table_events
LIMIT
1
)
UNION
(
SELECT
CONCAT(
title_clang_1,
' - ',
street,
' ',
zip,
' ',
district,
' ',
town,
' ',
additional
) label,
id
FROM
table_events
WHERE
offline IS NULL || offline = '|0|'
)
我最近将一个应用程序从 MySQL 5.5 迁移到了 MariaDB 10.3。 该应用程序的一部分是一个事件日历,用户可以在其中输入自己的事件,其中包含地址、城镇等详细信息。
我注意到其中一个查询 运行 这个软件不再与 MariaDB 一起工作,尽管语法应该还不错。
我已尝试返回 MySQL 5.5,查询再次运行。 我还在 MariaDB 10.3 上的 phpMyadmin 中进行了查询 运行,它显示了相同的结果,但以错误结尾:
ERROR 1064: You have an error in your SQL syntax; check the manual for the right syntax to use near 'UNION SELECT CONCAT(title_clang_1,' - ',street,' ',zip,' ',district,' ', town,' in line 1
这是查询:
SELECT
'choose' label,
'' id
FROM
table_events
LIMIT
1
UNION
SELECT
CONCAT(
title_clang_1,
' - ',
street,
' ',
zip,
' ',
district,
' ',
town,
' ',
additional
) label,
id
FROM
table_events
WHERE
offline IS NULL || offline = '|0|'
table "table_events" 包含此处列出的所有列:id、title_clang_1、street、zip、district、town、additional - 以及与此查询无关的更多列.
我希望输出所有离线字段填充零或 NULL 的事件,但我收到语法错误。
我很确定你的这个查询在 MySQL 中也不起作用(至少在较新的版本中)。 MySQL Documentation 明确指出:
To apply ORDER BY or LIMIT to an individual SELECT, place the clause inside the parentheses that enclose the SELECT
您需要在您的个人 SELECT
查询块周围使用括号,因为您在第一个查询中使用 LIMIT
:
(
SELECT
'choose' label,
'' id
FROM
table_events
LIMIT
1
)
UNION
(
SELECT
CONCAT(
title_clang_1,
' - ',
street,
' ',
zip,
' ',
district,
' ',
town,
' ',
additional
) label,
id
FROM
table_events
WHERE
offline IS NULL || offline = '|0|'
)