title: Multiple When case inside a join in MySQL
body: <p>I currently have a problem with the multiple <strong>when</strong> into <strong>case</strong>. When I remove the second <strong>when</strong>, it works. What is wrong with it?</p>
  
  <p>The reported MYSQL error is: </p>
  
  <pre><code>#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as param2 on param2.param_micro_site=i1.i_micro_site else null END )' at line 1
  </code></pre>
  
  <p>I tried these suggestions:</p>
  
  <p><a href="https://stackoverflow.com/questions/18991091/mysql-combining-multiple-when-conditions-in-case">MySQL - Combining multiple WHEN conditions in CASE</a></p>
  
  <p><a href="https://stackoverflow.com/questions/12523630/how-to-write-a-mysql-case-when-statement-with-multiple-search-conditions">How to write a MYSQL CASE WHEN statement with multiple search conditions?</a></p>
  
  <p>But it didn't solved my problem.</p>
  
  <pre><code>SELECT * FROM items i1
  join param on 
  (
  case 
      when (ITEM_ID=param_item_id and i_status=1 and item_page=164) 
      then param_item_id=ITEM_ID 
      when (i_micro_site&gt;=1 and i_status=7 and (EXISTS(select * from multiple where multiple_id=ITEM_ID and multiple_cat=21 and multiple_enum="item") || item_page=169)) 
      then (SELECT * from items i2 join pages on i2.item_page=p_ID and p_cat in (21,29,0) join param where param_micro_site=i1.i_micro_site and param_item_id in(i1.ITEM_ID,i2.ITEM_ID)) as param2 on param2.param_micro_site=i1.i_micro_site 
  else null END 
  )
  </code></pre>
  
  <p>Thank you</p>