Jump to content

Pivot table with multiple identical column names


Driesdk

Recommended Posts

Hi,

I want to pivot a table and at this moment i use:

SELECT e.guid AS id, e.guid AS guid,
TYPE , subtype, md.owner_guid AS owner_guid, site_guid, container_guid, md.access_id AS access_id, username, name, e.time_created, time_updated, name, e.enabled, banned, e.last_action, last_login, MAX( IF( msn.string = 'custom_profile_type', msv.string, NULL ) ) AS custom_profile_type, MAX( IF( msn.string = 'field1', msv.string, NULL ) ) AS field1,
MAX( IF( msn.string = 'field1', msv.string, NULL ) ) AS field1
FROM exp_metadata md
JOIN exp_metastrings msn ON md.name_id = msn.id
JOIN exp_metastrings msv ON md.value_id = msv.id
JOIN exp_users_entity u ON u.guid = md.entity_guid
JOIN exp_entities e ON e.guid = md.entity_guid
GROUP BY guid

You can see that I need the field 'field1' as a column with the value attached to it.

The problem is that there are multiple fields called 'field1' basicly the options of a multiselect that my users can choose.
Obviously using MAX I get the maximum value, ex. when they selected answer1, answer2 and answer3, this query will only fetch answer3.

 

I want to know if there is a way that instead of just 'answer3' I can have the value to be: answer1,answer2,answer3

 

I'm sorry if it is not really clear.

Thanks in advance.

Edited by Driesdk
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.