I have 2 tables
Table A
A1 | A2
1 | 2
2 | 3
3 | 4
Table B
B1 | B2
1 | 3
1 | 5
4 | 3
A1,A2,B1 and B2 are all ID's
I want to join Table A with Table B only when A.A1 = B.B1.
Select A.A1, A.A2, B.B2 from A JOIN B ON A.A1 = B.B1
should return
A1 | A2 | B2
1 | 2 | 3
1 | 2 | 5
But i want obtain data in this format, i would like final result as:
A1 | Col2
1 | 2
1 | 3
1 | 5
Extra question: How can i know from which column information comes?
A1 | Col2 | Table
1 | 2 | A
1 | 3 | B
1 | 5 | B
Thx for the help.
Edit1: Union wont work, i dont want to stack simply the fields from both tables, i want join data under a condition, but since A2 and B2 are ID´s of same type i would like to have data in a single collumn, and it would simplify future queries over the result.