Link to home
Start Free TrialLog in
Avatar of rotemweb
rotemweb

asked on

Mysql SELECT DISTINCT VALUES separated by a comma

Hi.
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
ASKER CERTIFIED SOLUTION
Avatar of Cornelia Yoder
Cornelia Yoder
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rotemweb
rotemweb

ASKER

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?

Thanks
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.
Ok, thanks. I thought, maybe a special unknown Query on MySQL ;o)
But i doubted it.

Cheers :)
Thank you for the points, but I am curious (for the future) what more I could have done to earn a grade of A?
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.  
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.
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.
Thanks.
OK, if that's the way you want to react to my suggestion for future behavior, see ya around, not.
Ok, you're right.