I an new to the group and this is my first time posting a question.
I have tbl1 that contains 3 columns (id, type, priority). The data looks like this:
id | type | priority
---+------+---------
1 | 1 | 1
2 | 2 | 1
3 | 1 | 2
I have tbl2 that contains all of my references. The data looks like this:
id | type1 | type2 | type3 | string
----+-------+-------+-------+---------
12 | 9 | 1 | 1 | single
12 | 10 | 1 | 2 | single
12 | 9 | 2 | 1 | carton
13 | 9 | 1 | 1 | low
13 | 9 | 2 | 1 | high
13 | 4 | 1 | 1 | low
14 | 9 | 1 | 1 | red
14 | 2 | 1 | 1 | red
14 | 9 | 2 | 1 | yellow
I want to join tbl2
on tbl1.type = tbl2.type2
where id=12
, type1=9
and type3=1
.
I also want to join tbl2
on tbl1.priority = tbl2.type2
where id=13
, type1=9
and type3=1
.
My resulting table should look like this:
id | type | priority
---+--------+---------
1 | single | low
2 | carton | low
3 | single | high
Does that make any sense? In essence, there is one reference table, but it needs to be joined over and over for the various columns in table 1. I don't know if it needs to be join, left join, inner left join.