简体   繁体   中英

Update with join and temp table

I have table that called hanpaka there I want to update the cardNum from temp table the connection between the two is IDMember and MemberId. but updating like this cause multiple cardNum not to the right MemberId why?

UPDATE Knowledge4All..Hanpaka
SET CardNum = (c.CardNumber )
FROM #Temp2 c inner join Hanpaka h on IDMember = h.MemberId`

Try using the alias in the update :

UPDATE h
    SET CardNum = c.CardNumber
FROM #Temp2 c JOIN
     Hanpaka h 
     ON c.IDMember = h.MemberId;

SQL Server does allow the table to be repeated in the update . However, it might get confused and your query might be doing a Cartesian product.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM