The UNION ALL clause is used to combine two streaming data sets. The field types and sequences of the two streaming data sets must be the same.
Syntax
select_statement
UNION ALL
select_statement;
Example
- Test data
Table 1: test_source_union1
a (VARCHAR) b (BIGINT) c (BIGINT) test1 1 10 Table 2: test_source_union2a (VARCHAR) b (BIGINT) c (BIGINT) test1 1 10 test2 2 20 Table 3: test_source_union3a (VARCHAR) b (BIGINT) c (BIGINT) test1 1 10 test2 2 20 test1 1 10 - Statement
SELECT a, sum(b), sum(c) FROM (SELECT * from test_source_union1 UNION ALL SELECT * from test_source_union2 UNION ALL SELECT * from test_source_union3 )t GROUP BY a;
- Result
d (VARCHAR) e (BIGINT) f (BIGINT) test1 1 10 test2 2 20 test1 2 20 test1 3 30 test2 4 40 test1 4 40