MySQL Forums
Forum List  »  Spanish

Re: Union de consultas
Posted by: Peter Brawley
Date: April 27, 2020 01:26PM

SELECT 
  p.prod_id, p.prod_nombre,
  group_concat( if(c.cod_id = 1, codprod_valor, null) ) AS Codigo1,
  group_concat( if(c.cod_id = 2, codprod_valor, null) ) AS Codigo2,
  group_concat( if(c.cod_id = 3, codprod_valor, null) ) AS Codigo3
FROM producto p
LEFT JOIN codprod cp  ON p.prod_id=cp.prod_id
INNER JOIN codigo c 	ON cp.cod_id=c.cod_id
GROUP BY p.prod_id, p.prod_nombre;

"Pivot table basics: rows to columns", https://www.artfulsoftware.com/infotree/queries.php

Options: ReplyQuote


Subject
Views
Written By
Posted
465
April 20, 2020 11:45AM
224
April 20, 2020 01:35PM
190
April 26, 2020 06:45AM
Re: Union de consultas
204
April 27, 2020 01:26PM
171
April 27, 2020 02:05PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.