title: GROUP_CONCAT mysql statement error
body: <p>I have tried mysql ststement for <a href="https://stackoverflow.com/questions/42282675/convert-rows-into-coumns-dinamiacally-for-some-table-with-concat-and-group-conca/42288693#42288693">dinamically rows to column</a> by followed <a href="https://stackoverflow.com/questions/17964078/mysql-query-to-dynamically-convert-rows-to-columns-on-the-basis-of-two-columns?noredirect=1&amp;lq=1">here</a> with query statement:</p>
  
  <pre><code>SET @sql = NULL;
  SELECT 
  GROUP_CONCAT(DISTINCT
    CONCAT(
      'MAX(CASE WHEN col = ''', 
      col,
      ''' THEN val END) as `',
      col, '`'
    )
  )INTO @sql
  FROM
  (
     SELECT A.id_a, D.id_c id_c,
            C.students students,
            CONCAT(B.`code`, '_', A.id_a) col,
            CONCAT(D.value_m, ',', D.value_n) val
    FROM table_a A
        INNER JOIN table_d D ON A.id_a =D.id_a
        INNER JOIN table_b B ON D.id_b=B.id_b 
        INNER JOIN table_c C ON D.id_c=C.id_c
  )dd;
  
  SET @sql = CONCAT('SELECT id_c, students,', @sql, '
          FROM(
              SELECT A.id_a, D.id_c id_c,
                  C.students students,
                  CONCAT(B.`code`, '_', A.id_a) col,
                  CONCAT(D.value_m, ',', D.value_n) val
              FROM table_a A
                  INNER JOIN table_d D ON A.id_a =D.id_a
                  INNER JOIN table_b B ON D.id_b=B.id_b 
                  INNER JOIN table_c C ON D.id_c=C.id_c
          )dd 
          GROUP BY id_c'
      );
  
  PREPARE stmt FROM @sql;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;
  </code></pre>
  
  <p>with result message:</p>
  
  <pre><code>Query OK, 0 rows affected
  Query OK, 1 row affected
  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 '', A.id_a) col,
              CONCAT(D.value_m, ',', D.value_n) val
          FROM table_a A    ' at line 1
  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 'MAX(CASE WHEN col = 'MAT_1' THEN val END) as `MAT_1`,MAX(CASE WHEN col = 'BIO_1'' at line 1
  1243 - Unknown prepared statement handler (stmt) given to EXECUTE
  1243 - Unknown prepared statement handler (stmt) given to DEALLOCATE PREPARE
  </code></pre>
  
  <p>I'm not familiar with sql statement like this, and what's wrong with that SQL QUERY</p>
  
  <p>Thanks...</p>