-1

enter image description here

hello everyone , i'm trying to generate new table using mysql that have difference value (which means eliminating duplicate) in the same column that have so much of string.

I already try group_concat(distinct column_name asc column_name separator ',') but it doesn't give the result i want ,

Important: I want different values inside a column

The picture no 1 is before sql and the number 2 is after group_concat sql ,it's still having duplicate there.

Thank you

Shadow
  • 33,525
  • 10
  • 51
  • 64
Lejiend
  • 1,219
  • 2
  • 16
  • 24

1 Answers1

1

You can do it but you should take PM77-1s advise and you should normalize your data.

That said... you can do it the following way with a temporary-table:

CREATE TEMPORARY TABLE temp (val CHAR(255));
SET @S1 = CONCAT("INSERT INTO temp (val) VALUES ('",REPLACE((SELECT GROUP_CONCAT( DISTINCT hashtag_name) AS data FROM hashes), ",", "'),('"),"');");
PREPARE stmt1 FROM @s1;
EXECUTE stmt1;
SELECT group_concat(DISTINCT(val)) as hashtag_name FROM temp;

I've made a working Fiddle. (because SQLFiddle is not workable these days I used rextester.com) http://rextester.com/HMUC89223

Result:

    hashtag_name
1   tido,makan,ittify,general,ittified,travel,lifestyle,minum,air,keyboard,lepak,gg,nice
Rik
  • 1,982
  • 1
  • 17
  • 30
  • thank you a lot!!!!!!!! , this is exactly what i want ,so happy , btw , i'm not storing data like that , that table in the picture is the result from more than one group_concat() command , thank you againnn!!! – Lejiend Oct 11 '16 at 10:36
  • @bathulahmahir Happy to help, and welcome to Stack Overflow. If this answer or any other one solved your issue, please mark it as accepted with the checkmark at the left. – Rik Oct 11 '16 at 10:44