Recently I needed to update a bunch of rows in mysql with information from another table. I will explain how to do this simple process.
- Open up phpmyadmin or similar database editor
- view the sql query below
UPDATE updatefrom p, updateto pp
SET pp.last_name = p.last_name
WHERE pp.visid = p.id
Lets say we have 2 tables one named main and one named updateto and one named updatefrom, In the first line we assign variables to these t tables (p and pp) from there we can call column names using this format table.columname. If we had first_name and last_name in both tables and wanted to update the “updateto” table with the info from “updatefrom” this is how you would write it.
Thanks! 🙂
That was exactly what I was looking for!
Regards,
Evert
thanx so much, Help me much 🙂
thank you! thank you! thank you!
Saved me from countless hours of more frustration 🙂
It’s so easy when you see it too!
I can’t believe it was that easy. You are the person. Your code explained things well. Thanks.
Thanks man, really helpful
Found this after a long search.
This should not be so difficult to find – in 1984 dBase II had this as a simple syntax. And so did all the subsequent DB programs.
Thank you for your extremely helpful and elegant solution.
This is one MYSQL command that is entirely intuitive.
Please keep up the great work – very much appreciated by us older chaps – I started in 1964 at Monash University in Melbourne Australia, start of a lifelong fascination with numbers.
Thank you.
It couldn’t be simpler.
This is so slick and simple. Thank you so much. Saved me hours!
This will also do…
UPDATE updateto pp INNER JOIN updatefrom p
on pp.visid = p.id SET pp.last_name = p.last_name
WHERE pp.status = ‘active’…
it is great thx
Thank you very much, saved me from hours of work 🙂
thx it really aim me
Wow that was easy. First search result furthermore.
Thanks for posting it.