last day (14 days later) » 

1:55 PM
6
A: Removing Duplicated Substrings

Saharsh ShahTry this: UPDATE tableA SET Mashup = IF(Keyword = Title, Keyword, CONCAT(Keyword, ' ', Title)); Check this SQL FIDDLE DEMO OUTPUT | KEYWORD | TITLE | MASHUP | |------------|------------|------------------| | Green | Green | Green | | Green | Wate...

 
Thank a lot for that! I think I partially understand what you have done here. I edited my question with another example with an extra column what would be done if there are multiple columns?
 
@BubblewrapBeast You're most welcome...
 
Also would this be done before the data is entered into the column? and would it automatically update from then on?
 
@BubblewrapBeast This query will update all the data which are already stored in that table. And if you want to insert new data in table thwn you have check at the time of insert.
 
Okay thank you! Also could you help me understand what would happen if this needed to be done across more columns like in my edited question. Thanks for your time
 
1:55 PM
@BubblewrapBeast The edit of quertion is possible because you are updateing a single column\
@BubblewrapBeast What do you want can you explain? You wan all column to checked or something else. Do you want to check all three columns? If all are same then use only one othewise concat all
 
Correct but the way i understood the IF statment was that if Keyword = title, but adding another column like "another" it would not check if keyword = another? Am I wrong? Thanks
 
Do you want to check all three columns? If all are same then return only one column data othewise concat all columns data
Do you want something like this?
 
Am I right?
 
So I would like the last column Mashup to contain everything from all the columns but nothing to be duplicated at all. I made another edit to the question that might explain a little better.
What you have done is basically there, what you just sent me, but in the last row i just want it to have 1 instance of Watermelon
 
2:01 PM
Can you post your table structure?
 
CREATE TABLE TableA
(`Keyword` varchar(10), `Title` varchar(10), `Another` varchar(10), `Mashup` varchar(100))
;

INSERT INTO TableA
(`Keyword`, `Title`, `Another`, `Mashup`)
VALUES
('Green', 'Green', 'Pink', 'Green Green Pink'),
('Green', 'Watermelon', 'Yellow', 'Green Watermelon Yellow'),
('Watermelon', 'Watermelon', 'Black', 'Watermelon Watermelon Black')
;

UPDATE tableA
SET Mashup = IF(Keyword = Title AND Keyword = Another, Keyword, CONCAT(Keyword, ' ', Title, ' ', Another));
this is what you did but I just changed the last column that is "Mashup"
the mashup column is a concat of the Keyword Title and Another column
The results from your code is close, but if a field has "Watermelon Watermelon" in it it doesnt remove the second watermelon
 
It did not work on id 4?
The result in Mashup if id 4 is: "Green Green Green Watermelon Sweet"
I would like it to be "Green Watermelon Sweet"
Does this make sense?
 

last day (14 days later) »