mysql - use result string from one table as column names for another query -
i trying trying simplify following query :-
select id, m_field_id_46 liverpool,m_field_id_47 london,m_field_id_48 belfast member_data
in way can dynamically create column names
select id, (select group_concat('m_field_id_',m_field_id,' ',m_field_label) member_fields) dist member_data
however not working. please help
i got working looking @ answer stackoverflow: -
set @liststr = ( select group_concat('md.m_field_id_',m_field_id,' `',m_field_label,'`') member_fields ); set @query := concat('select ', @liststr, ' member_data'); prepare stmt @query; execute stmt;
Comments
Post a Comment