0

I have a big database in which the website column values are malformed:

http://.www.123.com.au, http://.www.exampleurl.com

I want to correct these urls by removing this extra character . as:

http://www.123.com.au, http://www.exampleurl.com

I get these values by passing following select statement:

SELECT * 
FROM  `tbl_business` 
WHERE  `website` LIKE  'http://.%';
Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
ahmed
  • 490
  • 6
  • 13

1 Answers1

2
UPDATE your_table
SET your_field = REPLACE(your_field, 'http://.www', ' http://www')
WHERE your_field LIKE '%http://.ww%';

The REPLACE function is the simplest way I know to do this and once you know it is there it is a very useful tool. In this case I guess you would not need the WHERE clause if it is a small number of records, but I would add it so you work on only subset of the data, better for larger data sets and to avoid unintended consequences.

James Dewes
  • 171
  • 1
  • 19
  • 1
    While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – Michał Perłakowski May 06 '16 at 18:29