Sql-server – How to replace strings of a table from another table column

sql server

How do I update/replace the value of the first table from the list of my second table in SQL. Sorry im not so good in using replace() of SQL especially replacing from values base from different table

First table.

ID | Value
======================
 1 | Fruits[Apple]
 2 | Fruits[Apple,Mango]
 3 | Apple[Red,Green]

Second table

Search | Replace
=========================
Apple  | Orange
Green  | Yellow

Best Answer

In Oracle SQL it goes like this :

UPDATE FIRST_TABLE FT
   SET FT.VALUE =
       (SELECT ST.REPLACE FROM SECOND_TABLE ST WHERE FT.VALUE = ST.SEARCH)

But for this this to work properly, keep in mind that the attribute Search in the SECOND_TABLE must be unique, otherswise you'll need to rearange your query.