This the tags column where all terms should be listed only once. Would like to remove all additional words from this column. For example the below contant:
Lakshmi Bar & Restaurant, Dining & Leisure, Restaurants, Restaurants- Multi Cuisine, Hotel, , East#West, Malad East, Dafftary Road, Mumbai, Maharashtra, Features, , Lakshmi Bar & Restaurant, Dining & Leisure, Restaurants, Restaurants- Multi Cuisine, Hotel, , East#West, Malad East, Dafftary Road, Mumbai, Maharashtra, Cuisines, , Lakshmi Bar & Restaurant, Dining & Leisure, Restaurants, Restaurants- Multi Cuisine, Hotel, , East#West, Malad East, Dafftary Road, Mumbai, Maharashtra, Services, , Lakshmi Bar & Restaurant, Dining & Leisure, Restaurants, Restaurants- Multi Cuisine, Hotel, , East#West, Malad East, Dafftary Road, Mumbai, Maharashtra, Meal For Two, , Lakshmi Bar & Restaurant, Dining & Leisure, Restaurants, Restaurants- Multi Cuisine, Hotel, , East#West, Malad East, Dafftary Road, Mumbai, Maharashtra, Last Order/Booking (P.M), , Lakshmi Bar & Restaurant, Dining & Leisure, Restaurants, Restaurants- Multi Cuisine, Hotel, , East#West, Malad East, Dafftary Road, Mumbai, Maharashtra, BookUrTableId,
Should show as below:
Lakshmi Bar & Restaurant, Dining & Leisure, Restaurants, Restaurants- Multi Cuisine, Hotel, East, West, Malad East, Dafftary Road, Mumbai, Maharashtra, Features, Cuisines, Services, Meal For Two, Last Order/Booking (P.M), BookUrTableId
Where i tried to run the query and insert this into a table it gave an error as the content in this column was going too long and stops the execution of the query.
Also it would be preferred if i can get this done in mysql rather than using php or any other programming language.
Please help.
Best Answer
As has been mentioned, the database is perhaps not the best place to accomplish this; however, it can be done, using a stored function. You wouldn't want to rely on this in a live environment, bit it works.
If the following seems a bit primitive, that's an indication of the somewhat poor match between tool and task.
See this live demo: http://sqlfiddle.com/#!9/f32ee/1
The output from this function, given the input above:
Leading and trailing spaces and empty values are cleaned up automatically.
Again, the database not being the ideal tool is reflected in the benchmarks, which are highly dependent on input length and number of elements.
On the short and simple string shown above, the actual runtime on MySQL 5.5 on a 1 GHz Opteron 1218 is ~ 150 µsec, while the long string in the original question requires about 2400 µsec to process... which works out to a fairly substantial amount of time for large data sets.