zagors
zagors

Reputation: 13

SQL JOIN Table/ mapping

Helo, I have 2 simple tables and I must make one query which mapped data as a example below. I use Oracle SQL . Please help me :)

Table A

ID | A1 | A2 | A3 | Year
---+----+----+----+-----
1  |3   | 5  | 7  | 2000
2  |4   |    | 5  | 2001

Table B

Atribute |  Values
---------+------------
3        |  Apple
4        |  Lime
5        |  Pineapple
6        |  Apricot
7        |  Mango

Result

ID  | A1    |  A2        |  A3        | Year
----+-------+------------+------------+-------
1   | Apple |  Pineapple |  Mango     | 2000
2   | Lime  |            |  Pineapple | 2001

Upvotes: 0

Views: 47

Answers (1)

juergen d
juergen d

Reputation: 204854

Join the b table multiple times with different alias names

select a.id, a.year, 
       b1.values as a1,
       b2.values as a2,
       b3.values as a3
from a
left join b b1 on a.a1 = b1.attribute
left join b b2 on a.a2 = b2.attribute
left join b b3 on a.a3 = b3.attribute

Upvotes: 1

Related Questions