stored procedures - MySQL concat multiple rows into a single row -
i have query returns multiple rows such below in mysql:
attribute_name value ---------------------------------------- username emailuser domain mydomain.com
my required output follows:
username domain ----------------------------- emailuser mydomain.com
current sql:
select pa2.attribute_name, upa2.value product p inner join product_attribute pa on p.product_id = pa.product_id , pa.attribute_name = 'alias' inner join user_product_attribute upa on pa.product_attribute_id upa.product_attribute_id inner join user_product_attribute upa2 on upa.user_product_id = upa2.user_product_id inner join product_attribute pa2 on pa2.product_attribute_id = upa2.product_attribute_id , pa2.attribute_name in ( 'username', 'domain' ) p.product_name = 'email' , upa.value = 'emailalias@domainalias'
i have been looking @ group_concat, think wrong path.. suggestions?
nothing wrong group_concat
. following query slow small table, might not matter much.
select group_concat(if(`attribute_name`='username', `value`,'')) `username`, group_concat(if(`attribute_name`='domain', `value`, '')) `domain`, (your old table or select query) group `attribute_name`
Comments
Post a Comment