herbert ichama
herbert ichama

Reputation: 81

SQL Select all columns from two or more Unrelated tables

Table A
    A1 A2
1   1   2
2   2   2
3   1   3

Table B
  A1  A2
1  3   3
2  1   4
3  4   1 
4  5   0

Expected Result
Table C
   A1   A2
1  1    2
2  2    2
3  1    3
4  3    3
5  1    4
6  4    1 
7  5    0

Upvotes: 0

Views: 135

Answers (2)

tobypls
tobypls

Reputation: 849

If you want possible duplicates to be in the output, use UNION ALL:

SELECT A1, A2 FROM TableA
UNION ALL
SELECT A1. A2 FROM TableB

If you want duplicates to be grouped together, use UNION:

SELECT A1, A2 FROM TableA
UNION
SELECT A1. A2 FROM TableB

Upvotes: 1

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 31993

use union all

select a1,a2 from tbalea
union all
select a1,a2 from tbleb

Upvotes: 0

Related Questions