Connecting Tech Pros Worldwide Help | Site Map

MySQL query help required

Newbie
 
Join Date: Aug 2009
Posts: 3
#1: Aug 31 '09
I want to insert a number into field #2 if a number in field #1 matches x

Both fields are in the same table in the same db.

field 1 = CatParent
field 2 = CatParent2

What query do I run to effect this?
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 718
#2: Aug 31 '09

re: MySQL query help required


Do you want to update existing records or insert new records into the table?
Newbie
 
Join Date: Aug 2009
Posts: 3
#3: Aug 31 '09

re: MySQL query help required


Its an existing field that I want to enter for a record that I want to enter data for..

If 'record' CatParent = 20 insert into CatParent2 = xyz

There will be multiple records that CatParent will = 20
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 718
#4: Sep 1 '09

re: MySQL query help required


Then you need an UPDATE query. The query will look like

Expand|Select|Wrap|Line Numbers
  1. UPDATE table_name SET
  2. CatParent2 = 'xyz'
  3. WHERE CatParent = 20
Test this query on a test data before executing on real databse. It is always wise to backup your database before experiments :)
Newbie
 
Join Date: Aug 2009
Posts: 3
#5: Sep 6 '09

re: MySQL query help required


Worked like a dream... huge thanks mwasif!
Reply


Similar MySQL Database bytes