# Update Question

**URL:** <https://forum.kirupa.com/t/update-question/262148>\
**Category:** programming\
**Created:** [June 3, 2008, 6:51pm UTC](https://forum.kirupa.com/t/update-question/262148 "2008-06-03T18:51:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bear](https://forum.kirupa.com/u/bear)\
**Post date:** [June 3, 2008, 6:51pm UTC](https://forum.kirupa.com/t/update-question/262148/1 "2008-06-03T18:51:04Z")

</div>

Is there a way to update a certain part of field in an SQL query? Like a replace of some kind? like a string replace? I saw this somewhere. Can’t remember.

---

<div class="post-metadata">

**Author:** ![kdd](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@kdd](https://forum.kirupa.com/u/kdd)\
**Post date:** [June 3, 2008, 10:28pm UTC](https://forum.kirupa.com/t/update-question/262148/2 "2008-06-03T22:28:37Z")

</div>

I’m not understanding your question correctly, but I guess you can use str\_replace or str\_ireplace in PHP to do string replace.

---

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [June 4, 2008, 8:59am UTC](https://forum.kirupa.com/t/update-question/262148/3 "2008-06-04T08:59:51Z")

</div>

Depends what you mean and what version of SQL you are using!

You can use

REPLACE (\<search\>, \<find\>, \<replace\>)

in MSSQL to replace fields in an update - i.e.

```auto

UPDATE products SET Description = REPLACE(Description, 'Hello', 'Bye Bye') WHERE ID = 1

```

Not sure about the MySQL syntax - google it or look at MySQL docs online!

---

<div class="post-metadata">

**Author:** ![bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bear](https://forum.kirupa.com/u/bear)\
**Post date:** [June 4, 2008, 10:34am UTC](https://forum.kirupa.com/t/update-question/262148/4 "2008-06-04T10:34:37Z")

</div>

I meant like doing this in the SQL. Like replacing certain data in a field, because of this, without affecting the rest of it. How would the query look?

---

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [June 4, 2008, 10:39am UTC](https://forum.kirupa.com/t/update-question/262148/5 "2008-06-04T10:39:01Z")

</div>

I’m still not 100% understanding your problem -

The SQL statement I’ve posted will update 1 field in SQL (a field called Description) replacing any instances of the string ‘Hello’ with the string ‘Bye Bye’.

It’s all done in the query - no PHP or other langauages needed…

---

<div class="post-metadata">

**Author:** ![bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bear](https://forum.kirupa.com/u/bear)\
**Post date:** [June 4, 2008, 1:08pm UTC](https://forum.kirupa.com/t/update-question/262148/6 "2008-06-04T13:08:51Z")

</div>

Oops! I’ll try this out. I didn’t see your post because I didn’t refresh after taking my machine off of standby.

btw: what is that syntax called there?

The whole REPLACE (\<search\>, \<find\>, \<replace\>) part you did just there to show what the procedure looked like ? I’ve seen that in tutorial books. Is that just a way to display classes, params, and functions? Either way, I think it’s very helpful.

---

<div class="post-metadata">

**Author:** ![bear](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@bear](https://forum.kirupa.com/u/bear)\
**Post date:** [June 5, 2008, 2:45pm UTC](https://forum.kirupa.com/t/update-question/262148/7 "2008-06-05T14:45:15Z")

</div>

Updated:

Yep. This is correct. Thank you.

---

<div class="post-metadata">

**Author:** ![Charleh](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Charleh](https://forum.kirupa.com/u/Charleh)\
**Post date:** [June 5, 2008, 3:37pm UTC](https://forum.kirupa.com/t/update-question/262148/8 "2008-06-05T15:37:39Z")

</div>

That syntax is just generic old T-SQL or Transact SQL

REPLACE is just a SQL function which is available to most database implementations - this one I know works in MSSQL and I guess you are using MySQL
