title: MySql Pivot only returning half the columns
body: <p>I i've table  data like this</p>
  <pre><code>table name = tbl_fgm_career
  
  +------+-------+------+
  | name | value | year |
  +------+-------+------+
  | a1   | 12    | 1970 |
  | a2   | 56    | 1970 |
  | a1   | 65    | 1971 |
  | b7   | 555   | 1971 |
  | .    | .     | .    |
  | .    | .     | .    |
  | .    | .     | .    |
  | ab2  | 890   | 2019 |
  +------+-------+------+
  </code></pre>
  <p>And I wrote this Procedure to convert Year values to Columns</p>
  <pre><code>DELIMITER $$
  CREATE DEFINER=`root`@`localhost` PROCEDURE `pivot_question`()
  BEGIN
      SELECT
        GROUP_CONCAT(
      CONCAT(&quot;SUM(IF(year='&quot;, year, &quot;',value ,0)) AS '&quot;, year, &quot;'&quot;), &quot;\n&quot;
        ) INTO @answers
      FROM (
        SELECT DISTINCT year FROM tbl_fgm_career
      ) A;
  
      SET @query := 
        CONCAT(
          'SELECT name, ', @answers, 
          ' FROM tbl_fgm_career  GROUP BY name'
        );
  
      PREPARE statement FROM @query;
      EXECUTE statement;
  END$$
  DELIMITER ;
  </code></pre>
  <p>I had total 50 years (1970-2019). But when call this procedure I'm only getting till 1994. If I changed order by for year to DESC then I'm getting columns from (2019 to 1995)</p>
  <p>How to Solve this problem.</p>