sql - How do I replace an entire column in MySQL? -
Assume that I have the following table (Table 1) in MySQL:
First name Resident Bob USA I also have the following table (Table 2 ) In MySQL:
Resident Japan Canada Mexico I want to update Table 1 so that the end result is:
First name Resident Bob Japan Jen Canada Steve Mexico Right now, I am thinking to do the following: 1) Creating primary key on both tables May include 2) Drop the "residence" column of Table 1 3) Join tables. Is there an easier and more efficient way to update the column? An additive will take at least the linear time, when it should be a continuous time operation. In addition, using multiple update queries is difficult and slower.
Putting a line in a MySQL database looks fast and straightforward. I am thinking that there is an easy way to insert a column in a MySQL database.
Thank you!
There are incidents that can change the order of the rows in your tables, so you actually order You want to keep a column to differentiate.
If for the argument you thought that in whatever order you can rely on to store these lines, you can use the following:
Look at the Bela: < / P> update table1t join (select firstname, resident, @ rw: = @rw + 1 as row_number to table1 cross join (SELECT @rw: = 0) r) x on t. Firstname = x.firstname join (Select Resident, @ rx: = @ rx + 1 as row_number from Table 2 Cross Joy (SELECT @rx: = 0) r) y on y.row_number = x.row_number set t.residence = y .residence
Comments
Post a Comment