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
260
April 20, 2020 11:45AM
103
April 20, 2020 01:35PM
92
April 26, 2020 06:45AM
Re: Union de consultas
102
April 27, 2020 01:26PM
94
April 27, 2020 02:05PM


Sorry, only registered users may post in this forum.

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.