Ben
Ben

Reputation: 62394

Select all email addresses, implode by ;

I need to select all email addresses from a table, but implode them by ;. Is it possible for me to do this only utilizing a single MySQL query?

Upvotes: 3

Views: 6719

Answers (2)

Alin P.
Alin P.

Reputation: 44346

Yes,

With GROUP_CONCAT. But you should be aware that the default maximum returned length is 1024. Follow the link to see how you can work around this limitation (if needed).

Upvotes: 6

gen_Eric
gen_Eric

Reputation: 227260

SELECT GROUP_CONCAT(`emailAddress` SEPARATOR ';') AS `emails`
FROM table
WHERE id=4
GROUP BY id

Upvotes: 6

Related Questions