We help IT Professionals succeed at work.

MySQL query results as comma separated

Lightwalker asked
Dear Experts,

I have a frustrating problem that I thought would be simple but I am not finding the solution.

I have a Query below:

SELECT orderdetails.DetailsID  FROM orderdetails WHERE orderdetails.ProgramActivated = 2

this would give me results such as:


As you can see the results are in a list, where as what I want to do is have the results separated by a comma (,) to be used in another SQL query.

So the above results should be:

513, 516

I have been reading about GROUP_CONCAT which I was hoping would do it but I am not able to get it to work for me as the result is simply [BLOB] from the query below:

SELECT GROUP_CONCAT(orderdetails.DetailsID) AS DetailsID FROM orderdetails WHERE orderdetails.ProgramActivated = 2

Any suggestions?

Many thanks as always for your help.
Watch Question

Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

You could maybe use a sub query like this, a bit depending on how your other sql query would look like:
select field1, field2 from other_table where DetailsID in
  SELECT orderdetails.DetailsID
  FROM orderdetails
  WHERE orderdetails.ProgramActivated = 2

Open in new window

Hi, are you see'ing this in phpmyadmin?
Above the result should be a link/button for "+ Options"
Click it and select "Full Texts" and tick "Show BLOB contents", Then hit go and it should work


Dear stilliard,

you are a star. No I was not using phpmyadmin but I am using navicat for mysql as I tested the query.

As you mention about phpmyadmin I realized that I had not tested it inside my PHP script. When I did it shows up perfectly as comma seperated. So it is just in the navicat query editor it is showing up as blob.

Thank you for your insight.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.