title: SQL - IF STATEMENT throw error on SQL syntax
body: <p>I have a little bit bigger SQL query and having problem with it</p>
  
  <p>Error I get:</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 'GROUP_CONCAT(DISTINCT IF(po.repairmethod != 'E' OR (po.repairmethod = 'E' AND po' at line 6
  </code></pre>
  
  <p>QUERY i use:</p>
  
  <pre><code>SELECT c.vin, c.case_id, c.claimnumber, c.platenumber, c.axrmrs_id, c.insurer_memberid, c.country, c.date_created, c.totalloss, c.lastcalc_manufacturer_code, c.lastcalc_model_code, c.lastcalc_submodel_code, c.audavin_triggered, c.accident_date, c.registration_date, c.manufacturing_year,
                        cl.spareparts, cl.totalcosts, cl.laborhours, cl.laborcosts, cl.calculationdate, cl.paintlabor, cl.paintmaterial, cl.currency, car.manufacturer, car.model, car.submodel,
                        IFNULL(org.name, 0) as orgName,
                        GROUP_CONCAT(DISTINCT IF(po.repairmethod LIKE 'L%',po.text,NULL) ORDER BY 1) AS textL,
                        GROUP_CONCAT(DISTINCT IF(po.repairmethod = 'E',po.text,NULL) ORDER BY 1) AS textE
                        GROUP_CONCAT(DISTINCT IF(po.repairmethod != 'E' OR (po.repairmethod = 'E' AND po.guidenumber = 'N/A') AND po.repairmethod NOT LIKE 'L%',NULL) ORDER BY 1) AS textO
                      FROM axnmrs_cases AS c
                        LEFT JOIN axnmrs_calculations as cl on c.case_id = cl.case_id AND c.country = cl.country
                        LEFT JOIN axnmrs_positions as po on c.case_id = po.case_id
                        LEFT JOIN car_type as car on car.manufacturer_code = c.lastcalc_manufacturer_code AND car.main_type = c.lastcalc_model_code AND car.subtype_code = c.lastcalc_submodel_code
                        LEFT JOIN organization_list as org on org.memberId = c.insurer_memberid
                      WHERE c.vin= "U5YFF24128L064909"
                        GROUP BY c.vin, c.case_id, c.axrmrs_id
  </code></pre>
  
  <p>I was thinking problem was in brackets but I try to replace it unfortunately without success.</p>
  
  <p>Whole query work correctly without last GROUP_CONCAT LINE ( as error already say basicly )</p>
  
  <p>Any hints what's I am doing wrong or how to optimalizate this query?
  Thanks :)</p>
  
  <p>EDIT:
  error after added comma at the end of second GROUP_CONCAT:</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 ') ORDER BY 1) AS textO FROM axnmrs_cases AS c ' at line 6
  </code></pre>