König Gio König Gio - 1 month ago 7
SQL Question

Create a query using 2 tables with 3 columns and key id

I am trying to do a query and having a huge brain block. Here is the situation

Table 1

Account | Sen1 | Sen2
-------------------------------------
1234 1 0
1235 0 1


Table 2

ID | Name
--------------------------
1 Box


Results trying to achieve

Account | Name
------------------------
1234 Box
1235 Box


Code attempted

SELECT Table1.account, table1.sen1, table1.sen2, table2.id, table2.name

FROM table1
OUTER JOIN table2 ON (table1.sen1=table2.id) AND (table1.sen2=table2.id)

Answer

Not sure what you are trying to achieve. But the following should do:

SELECT m.Account, k.Name FROM Table_1 m 
INNER JOIN Table_2 k ON k.ID = m.Sen1 OR k.ID = m.Sen2
Comments