I have data like
id var1 var2
1 A1 B1
1 A2 B2
1 A3 B3
How can I get the data like
id v1 v2 v3 v4 v5 v6
1 A1 B1 A2 B2 A3 B3
Thanks in advance.
I have data like
id var1 var2
1 A1 B1
1 A2 B2
1 A3 B3
How can I get the data like
id v1 v2 v3 v4 v5 v6
1 A1 B1 A2 B2 A3 B3
Thanks in advance.
Given that you may potentially need more columns depending on how many records occur for each id
group, I would suggest an alternative approach using group concatenation:
SELECT
id,
GROUP_CONCAT(CONCAT_WS(',', var1, var2)) AS output
FROM yourTable
GROUP BY
id;
If you have more columns to add, you only would need to add additional columns to CONCAT_WS
.