1

I would like to replace all occurences of 's with s in myTable's name column. I tried REPLACE but it replaces all records. I want to do it for some customers.

Note: Customer is foreign key in myTable.

Thanks in advance

Update:

I tried some queries REPLACE(name, "'s", "s") from data where cust_id = 1 but this doesn't work

From one of questions I tried SELECT REPLACE(name, "'s", "s") from data where cust_id = 1. This is replacing all records in table

4
  • Have you tried the WHERE clause? Commented Feb 10, 2014 at 17:28
  • yes i tried where clause but it is not accepting where clause Commented Feb 10, 2014 at 17:29
  • What queries have you tried? Can you show us the SQL? Commented Feb 10, 2014 at 17:29
  • It's remotely possible that you are simply using it wrong. There's just no way that your DBA has disabled the WHERE clause. Commented Feb 10, 2014 at 17:30

1 Answer 1

4

A simple replace across all records in the table can be done with:

 UPDATE myTable
 set    name = REPLACE(name, '\'s', 's')

If you want to filter the records to be updated from another table, then you can do something like

 UPDATE myTable
 LEFT JOIN CustomerTable ON myTable.Customer = CustomerTable.Customer
 SET    name = REPLACE(name, '\'s', 's')
 WHERE  CustomerTable.Field > SomeCondition <== Replace with what you need.
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man. Why can't I thaught to use replace with update. Anyways, this helped me alot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.