我想检索使用Union
连接的查询结果集的前1个值SELECT TOP 1 * FROM
(
SELECT paused_time as end_time
FROM production_time
WHERE created_time = curdate()
UNION
SELECT resumed_time as end_time
FROM pause_timer
WHERE created_time = curdate()
UNION
SELECT end_time as end_time
FROM timer_idle
WHERE created_time = curdate()
) as end_time
ORDER BY end_time DESC
但无法得到预期的结果。
答案 0 :(得分:30)
据我所知,MySQL中没有TOP
个关键字。您需要的是Limit
:
SELECT * FROM
(
SELECT paused_time as end_time FROM production_time WHERE created_time = curdate()
UNION
SELECT resumed_time as end_time FROM pause_timer WHERE created_time = curdate()
UNION
SELECT end_time as end_time FROM timer_idle WHERE created_time = curdate()
) as end_time
ORDER BY end_time DESC
LIMIT 1