在Firebird中结合UNION ALL和ORDER BY [英] Combining UNION ALL and ORDER BY in Firebird
问题描述
这是我第一次尝试回答我自己的问题,因为有人可能会遇到这个问题,所以它可能是帮助。使用Firebird,我想使用UNION ALL合并两个查询的结果,然后对给定列上的结果输出进行排序。类似:
This is my first attempt at answering my own question, since someone may well run into this and so it might be of help. Using Firebird, I want to combine the results of two queries using UNION ALL, then sort the resulting output on a given column. Something like:
(select C1, C2, C3 from T1)
union all
(select C1, C2, C3 from T2)
order by C3
括号来自有效的语法其他数据库,并且需要确保UNION ALL(定义为在表上工作的操作,即无序记录集)的参数不尝试单独排序。但是我无法得到这个语法在Firebird中工作 - 怎么办呢?
The parentheses came from valid syntax for other databases, and are needed to make sure the arguments to UNION ALL (an operation that's defined to work on tables - i.e. an unordered set of records) don't try to be ordered individually. However I couldn't get this syntax to work in Firebird - how can it be done?
推荐答案
SELECT C1, C2, C3
FROM (
select C1, C2, C3 from T1
union all
select C1, C2, C3 from T2
)
order by C3
这篇关于在Firebird中结合UNION ALL和ORDER BY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!