title: How to create separate columns for values in Database
body: <p>I have an SQL query that displays information from different tables in a database. One of the fields is called PieceType and this contains values like PLT, CASE, CTN etc. Each company could have a different number of PieceTypes e.g. company 4 could have just PLT, but company 5 could have 10 different types. I want to display these types in separate columns like:</p>
  
  <pre><code>Plt | CASE | CTN
  </code></pre>
  
  <p>My SQL query:</p>
  
  <pre><code>SELECT  c.Name,
          jp.PieceType
  FROM customer c
  LEFT JOIN job_new jn ON ja.JobID = jn.ID
  LEFT JOIN job_pieces jp ON ja.JobID = jp.ID
  WHERE c.Company_ID = compid
  GROUP BY c.ID
  </code></pre>
  
  <p>Right now the query just displays one value from PieceTypes even though the company might have multiple piece types. I tried  <code>GROUP_CONCAT(DISTINCT jp.PieceType)</code> but that displays all the values in the same column. I need each piece to be in a separate column.
  Sample Database can be found on sqlfiddle: <a href="http://www.sqlfiddle.com/#!9/c34306/3" rel="nofollow">http://www.sqlfiddle.com/#!9/c34306/3</a></p>