LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-21-2013, 12:47 AM   #1
rsi.256
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Rep: Reputation: Disabled
Question mysql update statement


Hi

I have a table which looks like this
id | name | length | clone | null
1 | string 1 | 12345643 | string 1 | NULL |
2 | string 2 | 2345612 | string 2 | NULL |
3 | string 3 | 3421556 | string 3 | NULL |
4 | string 4 | 1236742 | string 4 | NULL |
5 | string 5 | 2312677 | string 5 | NULL |
6 |string 6 | 12786315 | string 6 | NULL |
7 | string 7 | 2341135 | string 7 | NULL |
8 |string 8 | 452189 | string 8 | NULL |
9 |string 9 | 124343 | string 9 | NULL |
10 | string 10 | 3432344 | string 10 | NULL |
.....

I wanted to replace all names columns having id> 5 to sequence.
Keep the first 5 entries the same but replace all others name = "sequence[id]"
and clone entry to be changed as clone = "sequence[id]"
The table should look like this

id | name | length | clone | null
1 | string 1 | 12345643 | string 1 | NULL |
2 | string 2 | 2345612 | string 2 | NULL |
3 | string 3 | 3421556 | string 3 | NULL |
4 | string 4 | 1236742 | string 4 | NULL |
5 | string 5 | 2312677 | string 5 | NULL |
6 |sequence 6 | 12786315 | sequence 6 | NULL |
7 | sequence 7 | 2341135 | sequence 7 | NULL |
8 |sequence 8 | 452189 | sequence 8 | NULL |
9 |sequence 9 | 124343 | sequence 9 | NULL |
10 | sequence 10 | 3432344 | sequence 10 | NULL |



i did use this command
UPDATE tablename
SET name = "sequence[id]"
where id >5;

but it didnt work

What is the error I did?
 
Old 12-21-2013, 12:52 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,253
Blog Entries: 1

Rep: Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289Reputation: 2289
Try this - note it includes space between sequence and id in new values as your "after" example showed.

Code:
UPDATE tablename SET name=CONCAT('sequence ',id), clone=CONCAT('sequence ',id) WHERE id>5;
 
Old 12-21-2013, 01:09 AM   #3
rsi.256
LQ Newbie
 
Registered: Dec 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Smile

Thanks it worked!
 
  


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
Running mysql from ssh & query statement has a Text Header in the SELECT statement? djlerman Linux - Server 6 11-19-2013 06:33 PM
mysql if else statement ohcarol Programming 4 05-23-2007 07:22 AM
MySQL If Statement troubles Centinul Programming 6 04-26-2006 01:31 AM
mysql sql statement help mrtwice Programming 4 12-02-2003 10:04 AM
mysql statement... johnyy Linux - Software 1 11-02-2003 03:30 AM


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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration