MySQL distinct string 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

&gt; 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.
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 involving apples, oranges, pears, and figs: MySQL group concat not showing distinct values when joined to another table

In 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

SELECT CONCAT('SELECT id,REPLACE(GROUP_CONCAT(DISTINCT frt),'','','', '') tag FROM (',
CONCAT('SELECT ',GROUP_CONCAT(fruitstr SEPARATOR ' UNION SELECT ')),') A GROUP BY id') 
INTO @TagSQL FROM
(
    SELECT REPLACE(CONCAT(REPLACE(QUOTE(tag),', ',CONCAT(''',',
    id,' id UNION SELECT ''')),',',id,' id'),',',' frt,') fruitstr FROM fruit
) A;
SELECT @TagSQL\G
PREPARE s FROM @TagSQL; EXECUTE s; DEALLOCATE PREPARE s;


YOUR SAMPLE DATA

mysql&gt; drop database if exists dinesh;
Query OK, 2 rows affected (0.38 sec)

mysql&gt; create database dinesh;
Query OK, 1 row affected (0.01 sec)

mysql&gt; use dinesh
Database changed
mysql&gt; create table fruit
    -&gt; (
    -&gt;     id int not null auto_increment primary key,
    -&gt;     tag varchar(100) not null
    -&gt; );
Query OK, 0 rows affected (0.28 sec)

mysql&gt; insert into fruit (tag) values
    -&gt; ('apples, oranges, apples'),
    -&gt; ('apples, pears, pears'),
    -&gt; ('figs, oranges, figs, oranges');
Query OK, 3 rows affected (0.03 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql&gt; select * from fruit;
+----+------------------------------+
| id | tag                          |
+----+------------------------------+
|  1 | apples, oranges, apples      |
|  2 | apples, pears, pears         |
|  3 | figs, oranges, figs, oranges |
+----+------------------------------+
3 rows in set (0.00 sec)

mysql&gt;


PROPOSED QUERY EXECUTED

mysql&gt; SELECT CONCAT('SELECT id,REPLACE(GROUP_CONCAT(DISTINCT frt),'','','', '') tag FROM (',
    -&gt; CONCAT('SELECT ',GROUP_CONCAT(fruitstr SEPARATOR ' UNION SELECT ')),') A GROUP BY id')
    -&gt; INTO @TagSQL FROM
    -&gt; (
    -&gt;     SELECT REPLACE(CONCAT(REPLACE(QUOTE(tag),', ',CONCAT(''',',
    -&gt;     id,' id UNION SELECT ''')),',',id,' id'),',',' frt,') fruitstr FROM fruit
    -&gt; ) A;
Query OK, 1 row affected (0.03 sec)

mysql&gt; SELECT @TagSQL\G
*************************** 1. row ***************************
@TagSQL: SELECT id,REPLACE(GROUP_CONCAT(DISTINCT frt),',',', ') tag FROM (SELECT 'apples' frt,1 id UNION SELECT 'oranges' frt,1 id UNION SELECT 'apples' frt,1 id UNION SELECT 'apples' frt,2 id UNION SELECT 'pears' frt,2 id UNION SELECT 'pears' frt,2 id UNION SELECT 'figs' frt,3 id UNION SELECT 'oranges' frt,3 id UNION SELECT 'figs' frt,3 id UNION SELECT 'oranges' frt,3 id) A GROUP BY id
1 row in set (0.00 sec)

mysql&gt; PREPARE s FROM @TagSQL; EXECUTE s; DEALLOCATE PREPARE s;
Query OK, 0 rows affected (0.00 sec)
Statement prepared

+----+-----------------+
| id | tag             |
+----+-----------------+
|  1 | apples, oranges |
|  2 | apples, pears   |
|  3 | figs, oranges   |
+----+-----------------+
3 rows in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql&gt;


GIVE IT A TRY !!!

P.S. Like I said in my earlier post, 

I TOLD YOU IT WAS CONVOLUTED !!!