I want to convert mysql rows to column, i tried but didnt get the required output. Thankyou In Advance. my table query is
First Table
CREATE TABLE `variant_to_group` (
`variant_to_group_ID` int(11) NOT NULL AUTO_INCREMENT,
`variant_group_ID` int(11) NOT NULL,
`variant_ID` int(11) NOT NULL,
PRIMARY KEY (`variant_to_group_ID`)
)
INSERT INTO `products_to_variants` (`products_to_variants_ID`, `variant_ID`, `variant_value`, `variant_group_ID`) VALUES
(1, 1, 'STD', 1),
(2, 1, '25', 1),
(3, 1, '50', 1),
(4, 1, '75', 1),
(5, 1, '100', 1),
(6, 2, 'USHA', 1),
(7, 2, 'SAM', 1),
(8, 2, 'Getzo', 1);
second table
CREATE TABLE `products_new` (
`product_ID` int(11) NOT NULL AUTO_INCREMENT,
`product_name` varchar(100) NOT NULL,
`brand_ID` int(11) NOT NULL,
`categories_ID` int(11) NOT NULL,
`product_variant_group_ID` int(11) NOT NULL,
PRIMARY KEY (`product_ID`)
)
INSERT INTO `products_new` (`product_ID`, `product_name`, `brand_ID`, `categories_ID`, `product_variant_group_ID`) VALUES
(1, 'Hero Honda CD 100', 1, 1, 1);
and the desired output required is -
product_name categories_ID variant_value_1 variant_value_2 Hero Honda CD 100 1 STD USHA Hero Honda CD 100 1 25 USHA Hero Honda CD 100 1 50 USHA Hero Honda CD 100 1 75 USHA Hero Honda CD 100 1 100 USHA Hero Honda CD 100 1 STD SAM Hero Honda CD 100 1 25 SAM Hero Honda CD 100 1 50 SAM Hero Honda CD 100 1 75 SAM Hero Honda CD 100 1 100 SAM Hero Honda CD 100 1 STD Getzo Hero Honda CD 100 1 25 Getzo Hero Honda CD 100 1 50 Getzo Hero Honda CD 100 1 75 Getzo Hero Honda CD 100 1 100 Getzo
i tried some of the search result from google and stackoverflow but i failed to generated above output
variant_to_groupbut the insert statement is for table:products_to_variants.products_to_variants(products_to_variants_IDint(11) NOT NULL,variant_IDint(11) NOT NULL,variant_valuevarchar(100) NOT NULL,variant_group_IDint(11) NOT NULL )