Search code examples
phpmysqlsqlgroup-bygroup-concat

Get GROUP_BY values as strings


I have this simple table called questions:

id | asker
 1 | Bob
 2 | Marley
 3 | Bob

I want to get a comma-separated list of the asker values. I use the following query:

SELECT GROUP_CONCAT(asker) FROM questions

This will result in:

Bob,Marley,Bob

I want it instead to result like this:

'Bob','Marley','Bob'

Thanks


Solution

  • The original didn't quite work in mySQL.

    Addressing Wrikken's very valid concern

    SELECT GROUP_CONCAT(concat('''',asker,'''')) FROM questions