I have 2 tables:
table1
id someval
-----------
1 23
2 56
3 76
4 456
5 53
6 67
7 12
8 43
9 99
10 567
11 55
12 6
13 55
14 56
15 1
16 444
17 66
18 89
19 6
table2
id someval
-----------
1 23.3
2 5.6
3 8.76
4 4.56
5 5.3
6 6.7
7 1.2
8 4.3
9 9.9
10 56.7
11 6.7
12 44.8
What query would join them and output (id is modified for second table):
table1AND2
id someval
-----------
1 23
2 56
3 76
4 456
5 53
6 67
7 12
8 43
9 99
10 567
11 55
12 6
13 55
14 56
15 1
16 444
17 66
18 89
19 6
20 23.3
21 5.6
22 8.76
23 4.56
24 5.3
25 6.7
26 1.2
27 4.3
28 9.9
29 56.7
30 6.7
31 44.8
Is there a way to do this in general for any 2 tables of any row size?
Use:
UNIONremoves duplicates;UNION ALLdoes not remove duplicates, and is faster for it.To insert into another table:
…that’s assuming there’s only two columns, id & somecol/etc, in the new table.