Created
June 13, 2012 09:16
-
-
Save stephenca/2922979 to your computer and use it in GitHub Desktop.
Pivot table query using mysql function GROUP_CONCAT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
t.email, | |
GROUP_CONCAT(if(a.attr = 'title', value, NULL)) AS 'Title', | |
GROUP_CONCAT(if(a.attr = 'forename', value, NULL)) AS 'First Name', | |
GROUP_CONCAT(if(a.attr = 'surname', value, NULL)) AS 'Last Name' | |
FROM targets t | |
JOIN attr_value_pairs a | |
ON t.attr_value_id = a.id | |
GROUP BY t.email; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment