mysql - Join Table With 2-Column Table, 1st Column Header, 2nd Column Value -


i have 2 tables in below diagram , want perform join on them. first table contains events, , second table contains attributes events.

schema

i want write query join 2 tables below , create output on bottom.

is possible in mysql? question hard google (or come title for!), apologize if duplicate.

right now, have this:

select * events e left join event_attributes ea on e.id = ea.event_id e.id = 1;

which produces 2 rows, 1 time_opened , 1 time_closed.

edit: want dynamic can add many attributes want , name becomes header column , value becomes rows's value.

you need 2 joins here:

select *  events e  left join event_attributes ea1 on e.id = ea1.event_id                                 , ea1.attribute_name = 'time_opened' left join event_attributes ea2 on e.id = ea2.event_id                                 , ea2.attribute_name = 'time_closed' e.id = 1; 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -