LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2008, 10:30 AM   #1
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 44
help with mysql command to update data in a table


Here is my setup

database name = database
table name = table
inside this table are several fields:
name
info1
info2
info3

Im trying to replace the data that is in info1, info2 and info3 for a specific name but am not sure how to do it.

Would this work? Just to replace info1, I want to get this working and then I'll edit it to include info2 and info3


update table set info1 = replace(info1,'currentstring','newstring') where name ='specificusername';


EDIT:

Ok so I got bold and tried out this commands:
update table set info1 = replace(info1,'currentstring','newstring') where name ='specificusername';

replacing the values for real database values and it worked. Now. What can I do to have one command to replace all 3 info? values?

Last edited by ncsuapex; 09-30-2008 at 11:14 AM. Reason: title
 
Old 09-30-2008, 11:19 AM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
Ok, I don't know what Database you are using, but read this.

In a nutshell:
Code:
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
Also, you can pre-pend table-names with database names(aka database.table). However, if you're on the sql command line, you can simply use a 'use' statement to specify what database you want the following operations done on:
Code:
use <database name>;
 
Old 09-30-2008, 11:32 AM   #3
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Original Poster
Rep: Reputation: 44
I was having a brain fart about which database to change the data in. It hit me after I posted the thread. Now that I have a working command how do I combine the command to include all 3 changes in one command? Ive tried separating them with a , and a ; but the command fails.



play with it long enough and I'll figure it out.


update table set info1 = newstring, info2 = newstring2, info3 = newstring3 where name ='username';

Last edited by ncsuapex; 09-30-2008 at 11:54 AM. Reason: .
 
  


Reply



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
Way to update mysql table 200+ times at once macie Programming 7 04-13-2005 11:45 PM
mySQL table update DropHit Linux - Software 5 02-04-2004 10:47 PM
MySQL non-realtime table-by-table mirroring Passive Linux - Software 1 01-20-2004 12:11 PM
How to import MS ACCESS Table including OLE filed into the MySQL Table ? myunicom Linux - General 1 11-28-2003 11:30 AM
Changing date format in MySQL table vous Linux - Software 8 09-03-2003 06:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:35 PM.

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
Open Source Consulting | Domain Registration