I have the following sample table.
drop table if exists fruit;
create table fruit
(
id int not null auto_increment primary key,
tag varchar(100) not null
);
insert into fruit (tag) values
('apples, oranges, apples'),('apples, pears, pears'),('figs, oranges, figs, oranges');
So the table looks like
> select tag from fruit;
+--------------------------------+
| tag |
+--------------------------------+
| apples, oranges, apples |
| apples, pears, pears |
| figs, oranges, figs, oranges |
+-----------------+
3 rows in set (0.00 sec)
How can I make the rows have unique fruits? For example, I would like to have the following resulting table.
tag
| apples, oranges |
| apples, pears |
| figs, oranges |
Any suggestions would be greatly appreciated.
Best Answer
You came to the right place !!! Hang onto something because you are going to roll on the floor laughing
I answered a similar question just like this back on
April 22, 2014
involvingapples
,oranges
,pears,
andfigs
: MySQL group concat not showing distinct values when joined to another tableIn your case, you need to assemble distinct fruits by the id it belongs to
Ready for a convoluted solution tailor made for you ?
PROPOSED QUERY
YOUR SAMPLE DATA
PROPOSED QUERY EXECUTED
GIVE IT A TRY !!!
P.S. Like I said in my earlier post,
I TOLD YOU IT WAS CONVOLUTED !!!