Coders Opinion

How to update mysql records from a select

Introduction

user

Robert-Jan de Dreu

Hey, I’m Robert-Jan de Dreu. A freelance software engineer, developing software since 2009. While using PHP and Javascript I build well structured and tested software.

About Me Hire Me
Featured

Database Management

How to update mysql records from a select

Posted by Robert-Jan de Dreu on .

While I was working on a project I needed to migrate some information from one table to the other. But only specific data. I was looking for a solution but I only found one easily for a mssql database. After some research I found a way to copy data from one to an other table while using where to filter:

UPDATE table1 tb1
INNER JOIN table2 tb2
ON tb1.id = tb2.sub_id
SET
tb1.field = tb2.field
WHERE tb1.field = ''

With this query you can easily transfer data from table2 to table1

user

Robert-Jan de Dreu

http://codersopinion.com

Hey, I’m Robert-Jan de Dreu. A freelance software engineer, developing software since 2009. While using PHP and Javascript I build well structured and tested software.