我想知道是否有办法将多个选择查询的结果显示为行。
如果我有以下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 |
+----------+-------------------+
由于
答案 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;