I have a table that has different rows, each row has a different key for the same items. I would like to create a mySQL query that puts the different keys as columns in a new table. Original table:
id locale key value
1 en description Great trip around cordoba's jklfjklfsjfdsk sdjk ds...
1 en highlights_1 horse back riding
1 en highlights_2 Asado
1 en highlights_3 Free drinks
Requested result:
id description highlights_1 highlights_2 highlights_3 ...
1 Great trip ar... horse back riding Asado Free drinks
The query I made (and gets me only one key/column in the new table is...)
SELECT activity.id,
activity_multilingual_fields_text.value AS activitydescription
FROM activity
LEFT JOIN activity_multilingual_fields_text ON activity_multilingual_fields_text.id = activity.id AND activity_multilingual_fields_text.locale = "en"
GROUP BY activity.id
I would appreciate your help!
key, or is it dynamic? If dynamic, you must create a dynamic SQL statement in application code or a stored procedure. Either way, there are many answers around here addressing it.