我有一个相当简单的 MySQL 查询:
(SELECT
id
, creation_date AS date
, 'order' AS type
FROM bus_orders
WHERE 1
UNION ALL SELECT
id
, start_date AS date
, 'contract start' AS type
FROM bus_contracts
WHERE 1
UNION ALL SELECT
id
, end_date AS date
, 'contract end' AS type
FROM bus_contracts
WHERE 1
) ORDER BY date DESC LIMIT 5
但是运行它会给我语法错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 'UNION ALL SELECT id, start_date AS date, 'contract start' AS type FROM bus_contr' 附近使用正确的语法
我敢肯定这是显而易见的,但我无法完全弄清楚。谁能发现我在这里做错了什么?