Skip to content Skip to sidebar Skip to footer

Joins And Restrictions For Different Columns At The Same Time

Can we use a join operation and make restrictions for different columns at the same time? I want to create a table on a Database (called DB1 in the example) based on three tables f

Solution 1:

You select is wrong (don't produce the expected result ) you should use two time the table t2 using an alias
and you should explicit assign the table t3 to value

SELECT t1.id1, 
   t1.id2, 
   t2.value
   t4.value
   t3.value
FROM db1.table1 t1 
   LEFT JOIN db1.table2 t2 
          ON t1.ID2=t2.ID2 
             AND value = 4 
   LEFT JOIN db1.table2 t4 
          ON t1.ID2=t4.ID2 
             AND value = 5             
   LEFT JOIN db1.table3 t3 
          ON t1.ID2=t3.ID2 
             AND t3.value = 7;

Post a Comment for "Joins And Restrictions For Different Columns At The Same Time"