MySQL remove any content after a comma

Tony Pearce
Tony Pearce used Ask the Experts™
on
Hi,
I have data in a field, for example 'red,red,green' I would like to be able to run an UPDATE on the database to remove any data after the first comma, including the comma, so above would show, 'red'

Any ideas?
Thanks
Tony
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Commented:
Try:

Update table_name set column=substring_index(column,',',1);

Author

Commented:
Thanks, I will try.

Author

Commented:
worked great. thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial