create table utst1(a int); insert into utst1 values (1),(1),(2),(2),(3),(3); create table utst2(b int); select * from utst1 union select * from utst2 order by 1;
Possible results:
a) +------+ | a | +------+ | 1 | | 1 | | 2 | | 2 | | 3 | | 3 | +------+ 6 rows in set (0.00 sec) b) +------+ | a | +------+ | 1 | | 2 | | 3 | +------+ 3 rows in set (0.01 sec)
[ Querying for Data (15%) - Using UNION ]
Answer:
b
UNION
will always remove duplicates from the resultset, even if the duplicates aren’t the result of theUNION
. (like in the example) If you need to have all rows returned, useUNION ALL
.a is actually the output of:
select * from utst1 union all select * from utst2;