SQL update from one Table to another based on a ID match

Discussion of open issues, suggestions and bugs regarding database management and administration tools for MySQL
Post Reply
marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

SQL update from one Table to another based on a ID match

Post by marsheng » Thu 04 Jun 2015 20:30

I've looked on the web and tried many options but I sill cannot get this right.

I tried using the query builder, but that too gave errors. This is what I want to do.

UPDATE members
SET members.MNZID = mnz_members.MNZID
WHERE members.MemID = mnz_members.MemID

Unknown column mnz_members.MemID
I do have the capitals correct.

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: SQL update from one Table to another based on a ID match

Post by marsheng » Fri 05 Jun 2015 02:10

For some reason, nearly every web example and solution provided only has one table listed in the update clause.

If you add both tables, then it works. !!!!!

UPDATE members , mnz_members
SET members.MNZID = mnz_members.MNZID
WHERE members.memID=mnz_members.memID

Most confused as I'm not updating mnz_members.

alexa

Re: SQL update from one Table to another based on a ID match

Post by alexa » Mon 08 Jun 2015 11:18

We are currently reviewing this post and will answer you as soon as possible.

alexa

Re: SQL update from one Table to another based on a ID match

Post by alexa » Mon 08 Jun 2015 13:34

The query should look as follows:

Code: Select all

UPDATE
  m
SET
  m.MNZID = mnz_m.MNZID
FROM
  members m
JOIN
  mnz_members mnz_m
ON
  m.memID=mnz_m.memID
Please also see the following https://msdn.microsoft.com/en-us/library/ms177523.aspx

Post Reply