LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-19-2008, 11:40 AM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Rep: Reputation: 39
Moving and replacing entries in a MySQL database


Hi there --

I am running a MySQL, version 14.12 Distrib 5.0.45, for redhat-linux-gnu (x86_64) using readline 5.0, database on one of our servers. I would like to move a group of similar entries in one set of fields to another set, and subsequently replace the data that was moved from the original group of fields with another set of similar information.

Is this possible, and if so, what would be the correct syntax to use? Thanks.
 
Old 04-19-2008, 03:43 PM   #2
marquardl
Member
 
Registered: Apr 2008
Posts: 100

Rep: Reputation: 15
all in a single query?

MySQL has quite esoteric possibilities like this one (just a modified OSC sample for a select statement):
Code:
select cd.categories_name, c.categories_image, cd.categories_htc_title_tag, cd.categories_htc_description from table_categories c, table_categories_description cd where c.categories_id = '999' and cd.categories_id = '777' and cd.language_id = '666';
Note the fragile mix of multiple tables and fields in a single statement.

If you really want to make all changes within a single SQL statement, then you better wade through MySQL documentation and prepare for a lot of testing. Within in PHP or C/C++ code you better break down the procedure into multiple queries - makes it easier to maintain.

No ready to use SQL statement, sorry!

KDE Programs Naming Convention

Last edited by marquardl; 05-01-2008 at 04:01 AM.
 
Old 04-21-2008, 02:44 PM   #3
kaplan71
Member
 
Registered: Nov 2003
Posts: 809

Original Poster
Rep: Reputation: 39
How about this

Hi there --

Thanks for your reply. How about this: What command can I use to replace all instances of one data entry in a field with a new one. For example, if I want to replace all instances the tape ID 12345 in the 'local' field with that of 678910 in the same 'local' field, what command would I use? Thanks.
 
Old 04-21-2008, 03:01 PM   #4
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Not exactly sure this is how the table you are describing looks (your use of the word field is throwing me off), but if your tape ID is all that is in the field, it should be something similar to:

Code:
update local set tapeID = '678910' where tapeID = '12345';
HTH

Forrest
 
Old 04-21-2008, 09:06 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Yeah, the core syntax is
Code:
UPDATE <tablename>
SET <columnname> = <newval>
WHERE <columname> = <oldval>
Tables are regarded as being built up of rows & columns.

Here's the MySQL docs: http://dev.mysql.com/doc/refman/5.0/en/
see http://dev.mysql.com/doc/refman/5.0/en/update.html for the UPDATE syntax.
 
  


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
MySQL - can it handle a database with 300,000,000 entries? Micro420 Linux - Software 4 03-22-2007 12:22 AM
Duplicate entries in RPM database -- different architectures fiservguy Red Hat 3 01-19-2006 07:17 PM
rpm database missing entries? dtashima Red Hat 0 10-29-2004 08:18 AM
Moving mySQL database subnet_rx Linux - Software 12 06-30-2004 04:41 PM
Blank entries inserted into mysql database sandoz Programming 4 09-22-2003 03:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:48 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