title: Joining two tables based on column value
body: <p>I need to join different tables if a condition meets on the first join,  so, if a column of the first join has a value 1 then do a join with one table, but if the value has 2 then do the join with another table, something like this but MySQL give an error</p>
  <pre><code>SELECT col1, col2, col3,...,col8
  FROM table1 AS tb1
  INNER JOIN table2 AS t2 ON tb1.id = tb2.id
  INNER JOIN table3 AS t3 ON tb2.id = tb3.id
  CASE
      WHEN tb2.col2 = 1   THEN INNER JOIN table4 ON id = col1
      WHEN tb2.col2 = 2   THEN INNER JOIN table5 ON id = col3
      WHEN tb2.col2 = 3   THEN INNER JOIN table6 ON id = col5
  END    
  WHERE tb1.id = 13;
  </code></pre>