Mysql SELECT DISTINCT VALUES separated by a comma

I have a  MySQL table, with a field named 'actors'.
In this field are found names separated by a comma.

What would be the better method to SELECT DISTINCT actors ?...
Put everything in an array and explode it then sort it? Or woud there be a simpler Query to do it?
Thank you
Who is Participating?
Cornelia YoderConnect With a Mentor ArtistCommented:
SELECT DISTINCT works on the entire field, so your best bet is to retrieve the field and then use php to get your distinct values.  Explode() is a good approach, and then you could use array_unique to remove duplicate values.
rotemwebAuthor Commented:
So your solution would be:

- SELECT actors FROM mytable
- Then put all values in a variable (wouldn't it be too long? the table is not too big- yet)
- Explode the variable
- Use array_unique to remove duplicate

...and use that array

Is that it?  
No other solution?

Cornelia YoderArtistCommented:
That seems like the easiest method to me.  You could normalize your database so that you have only actor name per field, and then use MySQL Select Distinct, but if you must have a variable number of comma-separated names in the table, then I don't see any better choice.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

rotemwebAuthor Commented:
Ok, thanks. I thought, maybe a special unknown Query on MySQL ;o)
But i doubted it.

Cheers :)
Cornelia YoderArtistCommented:
Thank you for the points, but I am curious (for the future) what more I could have done to earn a grade of A?
rotemwebAuthor Commented:
Well, it is a matter of how intricate is the question and the answer.
 I basically suggested the answer, and you confirmed it.
 If, thanks to your answer  I had accessed to the best solution possible, something I hadn't imagined (it happened to me here many times) I would have rated 'excellent'.
( It was very good though )

But it is not due to your knowledge (that i don't question at all);  just to the question / range of answers.  
Cornelia YoderArtistCommented:
Well, for the future, please keep in mind that sometimes the correct answer is -- there isn't a way.  

While it's true that I confirmed your thought, and added the array_unique function rather than your suggested sorting, it's not my fault that there wasn't a slick solution that you were hoping for.
rotemwebAuthor Commented:
A rating is subjective.If not, you would rate yourself.
"Flagrant injustice" doesn't apply here.
 So please let's close that topic, it is of poor interest.
Cornelia YoderArtistCommented:
OK, if that's the way you want to react to my suggestion for future behavior, see ya around, not.
rotemwebAuthor Commented:
Ok, you're right.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.