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:
Plt | CASE | CTN
My SQL query:
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
Right now the query just displays one value from PieceTypes even though the company might have multiple piece types. I tried GROUP_CONCAT(DISTINCT jp.PieceType)
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: http://www.sqlfiddle.com/#!9/c34306/3