Home > Enterprise >  How to map column data from two tables into a 3rd in SQL?
How to map column data from two tables into a 3rd in SQL?

Time:07-01

Table A

col 1 col 2
a b
c d

Table B

col 1 col 2
a e
b f
c g
d h

Result :

col 1 col 2
e f
g h

CodePudding user response:

You can join table B twice such as

SELECT B1.col2 AS col1, B2.col2
  FROM A
  JOIN B B1
    ON B1.col1 = A.col1
  JOIN B B2 
    ON B2.col1 = A.col2

Demo

  • Related