0

我有以下查询:

  SELECT table1.data AS table1_data,
     table2.data AS table2_data,
     table3.data AS table3_data
    FROM table1, table2, table3
GROUP BY table1.data, table2.data, table3.data

结果:

table1_data  | table2_data  | table3_data
------------------------------------------
2012-11-15   | 2012-11-18   | 2012-11-20
2012-11-16   | 2012-11-18   | 2012-11-23
2012-11-17   | 2012-11-18   | 2012-11-27

当我期望:

all_tables_data
----------------
2012-11-15
2012-11-16
2012-11-17
2012-11-18
2012-11-18
2012-11-18
2012-11-20
2012-11-23
2012-11-27

我已经“用谷歌搜索”了一些术语,但我无法描述这种类型的查询,所以没有找到任何可以帮助解决问题的方法。

4

2 回答 2

2

你应该使用“UNION ALL”而不是“GROUP BY”:

select table1.data from table1
union all
select table2.data from table2
union all
select table3.data from table3
于 2012-12-04T01:10:11.747 回答
1

union不需要group by

SELECT data AS all_tables_data FROM table1
UNION ALL
SELECT data AS all_tables_data FROM table2
UNION ALL
SELECT data AS all_tables_data FROM table3
于 2012-12-04T01:09:51.280 回答