mysql - Join two rows of the same table which points to the same thing in another table -


tablea

key    |    col1         | col2        | =========================|=============| 1      |    1            |1            |   2      |    2            |3            | 3      |    10           |5            | 4      |    55           |7            | 

tableb

b_key    |    col3         | =========================| 1      |    name1        | 2      |    name2        | 3      |    name3        | 7      |    name7        |  10     |    name10       | 55     |    name55       | 

expected result

|    col1_join    | col2_join ==================|============= |    name1        |name1 |    name2        |name3 |    name10       |name5 |    name55       |name7 

i have 2 tables , b. col 1 , col 2 foreign keys refer table b's pk.

what want way join these 2 tables , b , corresponding col3.

i tried

select *      tbl_a  inner join      tbl_b  on      tbl_a.col1 = tbl_b.b_key  or     tbl_a.col2 = tbl_b.b_key  

you may

select  b1.col3 col1_join, b2.col3 col2_join tablea  left join tableb b1 on b1.b_key = a.col1 left join tableb b2 on b2.b_key = a.col2 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -