So i have a mysql table, like the one above where the column Product
ID | Product_Name |
---|---|
1 | text1 |
2 | text1 \n |
3 | text2 |
4 | text3 |
5 | text4 \n |
My problem is that i'm not very smart - and have introduced ALOT of products to my table with an new-line in the end. With the following query i figured out, that i had 200k+ rows with a new line:
SELECT * FROM `my_product_table` WHERE `Product_Name` REGEXP "\n"
I'm looking for a way to trim - all "Product_Name" with a newline if another product with that exact name does not exist already - and if it exits already, i just want to remove it.
I figured the easyiest way was to:
- Trim all rows possible - since it will throw an error if a duplicate exists, so nothing will happen
- After everything possible is trimmed - delete the rest
Step 2. is should be easy, by just modifying my query above - but my MYSQL knowledge is sadly lacking a little, when i'm trying step 1. Is this the way to do it? and is it even possible?
EDIT I think i was not clear about the new line, i dont know how to write it in tables on stack, but see this image https://i.stack.imgur.com/kG5oD.jpg - thats how the duplicate value with the "new line" looks