sql - Key and value lookup in relational database -


i have data follows

table1 ------  |b 1  |2 3  |4  table2 ------ c  |d 1  |11 2  |12 3  |13 4  |14 

the expected output is

d , d -------- 11, 12 13, 14 

the logic behind output is, need create view view returns me column d of table2 corresponding column or column b table1 matching column c of table2. view act lookup finding values in table2 based on keys in table1. if in case, 1 of key in table1 not have corresponding value in table2 pair should not reported.

data setup:

create table table1     ("a" number, "b" number);  insert      table1 ("a", "b")       values (1, 2)     table1 ("a", "b")       values (3, 4) select * dual;  create table table2     ("c" number, "d" number);  insert      table2 ("c", "d")       values (1, 11)     table2 ("c", "d")       values (2, 12)     table2 ("c", "d")       values (3, 13)     table2 ("c", "d")       values (4, 14) select * dual; 

i tried joins string concatenation horrible. kognitio database of oracle syntax works here. referred this no use. dwh environment , apply logic on surrogate keys.

you want join twice:

select t2a.d, t2b.d table1 t2 join      table2 t2a      on t1.a = t2a.c join      table2 t2b      on t1.b = t2b.c; 

note use of 2 different aliases table2. how these distinguished in query.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -