LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sql select replace (https://www.linuxquestions.org/questions/linux-newbie-8/sql-select-replace-4175461067/)

wackysiya 05-07-2013 03:40 PM

Sql select replace
 
Sql select replace
Hi All,

I had a query related to sql select replace command.
i have a table named clusters and it looks like this


Code:

name characteristics
sample 1.1 parent
sample 1.2 clone
sample 1.3 clone
sample 1.4 parent
sample 1.5 parent
sample 1.6 clone
sample 2.1 parent


I want all my entries named "sample" to" data" I need like bulk entries changed.

The table should look like this

clusters


Code:
name characteristics
data 1.1 parent
data 1.2 clone
data 1.3 clone
data 1.4 parent
data 1.5 parent
data 1.6 clone
data 2.1 parent

Is it possible using a select replace and update statement?
Please do help

I did use this

SELECT REPLACE ('clusters','sample','data');

but it didnt work

I also thought it might because of spacing between sample and number
I used this

SELECT REPLACE ('cluster','sample*','data*');
but that didnt work too.

Please advise

chrism01 05-07-2013 06:10 PM

If the table is named 'clusters' & the column is named 'name', then
Code:

update clusters
set name='data'
where name = 'sample';

commit;

https://dev.mysql.com/doc/refman/5.1/en/update.html
In fact you should bookmark that entire site, if you use MySQL.
If you use another DB, bookmark the relevant site and read it.

The code above is basic SQL, so should work on any RDBMS.


All times are GMT -5. The time now is 02:53 PM.