Appending rows returned from different queries into one(将从不同查询返回的行附加到一个)
问题描述
我有 3 个查询,它们从 3 个不同的表(带连接)中获取数据,并且它们的列名几乎相同(或者我使用 AS
关键字使它们相同).完成 3 个查询后,我想合并它们的结果,因此看起来它们来自一张表.请看下面的代码.
I am having 3 queries, which takes data from 3 different tables (with joins) and their column names are pretty much same (or I made them same by using AS
keyword). Once the 3 queries are completed, I want to combine their results, so it looks like they are coming from one table. Please have a look at the below codes.
第一个查询
第二次查询
第三次查询
完成这些查询后,我想合并它们的结果.这意味着,2nd Query 返回的行将附加在 1st 查询返回的行之后. 第三个查询返回的行将附加在 1st 查询返回的行之后第二问.最后,我想按 Updated_Date
Once these queries are done, I want to combine their results. Which means, Rows returned by the 2nd Query will be appended after the rows returned by the 1st query. Rows returned by the 3rd query will be appended after the rows returned by the 2nd query. Finally, I want to sort the final result by Updated_Date
我该怎么做?
推荐答案
使用 UNION
组合查询:
排序可以通过在最后一个查询后附加一个 order by 子句来完成,如下所示:
Sorting can be done by appending an order by clause after the last query, as follows:
注意field1
、field2
...可以是字段名称或字段编号(从1开始).
Note that field1
, field2
... can be field names or field numbers (starting from 1).
这篇关于将从不同查询返回的行附加到一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!