lilmer Posted September 10, 2014 Share Posted September 10, 2014 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 Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted September 10, 2014 Share Posted September 10, 2014 (edited) 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 September 10, 2014 by jazzman1 Quote Link to comment Share on other sites More sharing options...
Barand Posted September 10, 2014 Share Posted September 10, 2014 This should be more efficient than using dependent subqueries UPDATE tb_one t1 INNER JOIN tb_two t2 ON t1.id = t2.cID SET t1.email = t2.email Quote Link to comment Share on other sites More sharing options...
lilmer Posted September 11, 2014 Author Share Posted September 11, 2014 Thank you people, I'd just try this using my navicat, works perfect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.