gpt4 book ai didi

mysql - UNION SELECT CONCAT 在 MariaDB/MySQL 之间的工作方式不同

转载 作者:太空宇宙 更新时间:2023-11-03 11:23:36 25 4
gpt4 key购买 nike

我最近将一个应用程序从 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_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 查询 block 周围使用括号,因为您在第一个查询中使用了 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 - UNION SELECT CONCAT 在 MariaDB/MySQL 之间的工作方式不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56824451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com