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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -