在 Firebird 中结合 UNION ALL 和 ORDER BY [英] Combining UNION ALL and ORDER BY in Firebird

查看:33
本文介绍了在 Firebird 中结合 UNION ALL 和 ORDER BY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次尝试回答我自己的问题,因为有人可能会遇到这个问题,所以它可能会有所帮助.使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆