LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-07-2013, 03:40 PM   #1
wackysiya
LQ Newbie
 
Registered: Mar 2013
Posts: 12

Rep: Reputation: Disabled
Question 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
 
Old 05-07-2013, 06:10 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,301

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.

Last edited by chrism01; 05-07-2013 at 06:11 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL select/NULL question action_owl Programming 3 12-23-2010 08:24 PM
sql - select, count, join, group true_atlantis Programming 1 11-19-2008 10:07 PM
SQL SELECT Group by 2 conditions MicahCarrick Programming 1 01-30-2007 10:02 PM
Sql + Oracle Select If ???? smaida Programming 11 12-15-2004 08:13 PM
Bizarre SQL select query acid_kewpie Programming 6 01-20-2004 12:47 PM


All times are GMT -5. The time now is 06:44 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration