mysql - How to display one table values as table row and display values for this from another table -


i'm trying combine , display 2 table bellow, first table structure is,enter image description here

my second table is,enter image description here

and expected result is,enter image description here

i tried could't result

select t2.field_value t2.name content_fields t1 join content_fields_type_richtext_data t2 on t1.id = t2.field_id; 

is there mistake in table structure. how result. please one

mysql not have pivot function can convert row data columns using aggregate function case expression:

select t2.object_id,   max(case when t1.frontend_name = 'bride photo' t2.field_value end) `bride photo`,   max(case when t1.frontend_name = 'bridegroom photo' t2.field_value end) `bridegroom photo`,   max(case when t1.frontend_name = 'bride description' t2.field_value end) `bride description`,   max(case when t1.frontend_name = 'groom description' t2.field_value end) `groom description`,   max(case when t1.frontend_name = 'wishes' t2.field_value end) `wishes` content_fields t1 inner join content_fields_type_richtext_data t2    on t1.id = t2.field_id group t2.object_id; 

if have unknown or dynamic number of values, want use prepared statement result:

set @sql = null; select   group_concat(distinct     concat(       'max(case when t1.frontend_name = ''',       frontend_name,       ''' t2.field_value end) `',       frontend_name, '`'     )   ) @sql content_fields;  set @sql    = concat('select t2.object_id, ', @sql, '              content_fields t1             inner join content_fields_type_richtext_data t2                on t1.id = t2.field_id             group t2.object_id');  prepare stmt @sql; execute stmt; deallocate prepare stmt; 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -