I have the following two tables, one stores order information, one stores key|value information.
There is no CD = D for key COLOR_CD. I would like to join both tables to get all orders irregardless of the key|value pair not found in the MASS_DECODE table.
Can i get some help please 😀
ORDER_INFORMATION
ORDER_NUMBER |COLOR_CD |
----------------|-----------|
1 |A |
2 |B |
3 |C |
4 |D |
MASS_DECODE
KEY |CD |VALUE |
------------|---------------|-----------|
COLOR_CD |A |Green |
COLOR_CD |B |Blue |
COLOR_CD |C |Red |
SIZE_CD |A |Large |
SIZE_CD |B |Medium |
SIZE_CD |C |Small |
SQL:
select order_number, cd, value
from order_information
left outer join mass_decode
on (color_cd = cd)
and key = 'COLOR_CD';
Outcome:
ORDER_NUMBER |CD |VALUE |
----------------|-----------|-----------|
1 |A |Green |
2 |B |Blue |
3 |C |Red |
Expected:
ORDER_NUMBER |CD |VALUE |
----------------|-----------|-----------|
1 |A |Green |
2 |B |Blue |
3 |C |Red |
4 |D |NULL |
EDIT: I am sorry i have presented incorrect information for my tables. Since been corrected.
SQLFiddle
upd:
According to your updates:
SQLFiddle