Jump to content

Recommended Posts

Hello, 

 

Anyone can suggest me what is the best way to update table records. I'm kinda scared to make an update on a table because it may damage the system and I am not really good on SQL commands.

 

Right now I just made a process on PHP to update table records. It does update email records on but it stop because of the limit of loading the page. Is there anyway accurately update all the data of the table.

 

Here is what I want to achieve.

 

I have a table with an "email" field on it, those email data from  "email" field on tb_one must be change to cID records base on tb_two. 

 

tb_one 

Field =

  - id

  - email

  - etc.

 

tb_two

Field = 

  - id

  - email (same as on tb_one)

  - cID

 

Link to comment
https://forums.phpfreaks.com/topic/290969-update-thousands-of-record/
Share on other sites

A common, standard sql way of doing this is:

UPDATE tbl_one t1 
SET t1.email = (SELECT t2.email FROM tbl_two t2 WHERE t1.id = t2.cID)
WHERE EXISTS (SELECT 1 FROM tbl_two t2 WHERE t1.id = t2.cID)

PS - Don't forget to backup your data before trying this ( for every case)

Edited by jazzman1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.