输出结果来自多个select语句作为行

时间:2014-05-30 15:20:37

标签: sql oracle select rows

我想知道是否有办法将多个选择查询的结果显示为行。

如果我有以下SELECT查询:

SELECT count(*), MAX(created_date) from TABLE1;

SELECT COUNT(*), MAX(created_date) from TABLE2;

我期望的输出是

 +----------+-------------------+
 | Count(*) | MAX(created_date) |
 +----------+-------------------+
 |   234    |     10-may-14     |
 |   847    |     03-Apr-14     |
 +----------+-------------------+

由于

1 个答案:

答案 0 :(得分:3)

您可以使用UNION [ALL]

SELECT COUNT(*), MAX(created_date) from TABLE1
UNION ALL
SELECT COUNT(*), MAX(created_date) from TABLE2;

如果您想确定每一行的来源,您可以创建另一列:

SELECT 'TABLE1' AS Source, COUNT(*), MAX(created_date) from TABLE1
UNION ALL
SELECT 'TABLE2' AS Source, COUNT(*), MAX(created_date) from TABLE2;