[英]update table in mysql by taking data from another table?
I am using mysql.i have 2 tables NOTE_ONE and NOTE_TWO. 我正在使用mysql.i有2个表NOTE_ONE和NOTE_TWO。 each table has three columns as ID and NAME and MID.
每个表都有三列,分别是ID,NAME和MID。 i need to update NOTE_TWO table's MID column with data from MID column of NOTE_ONE.
我需要使用NOTE_ONE的MID列中的数据更新NOTE_TWO表的MID列。 but condition is NOTE_ONE and NOTE_TWO tables NAME should be equal.
但条件是NOTE_ONE和NOTE_TWO表NAME应该相等。 PLease suggest me how to write query for this?
请建议我如何为此编写查询?
Thanks! 谢谢!
This should do the trick, 这应该可以解决问题,
UPDATE NOTE_TWO n2, NOTE_ONE n1
SET n2.MID = n1.MID
WHERE n1.NAME = n2.NAME
Hope this helps 希望这可以帮助
尝试这个
UPDATE note_two n2 set mid = (SELECT mid from note_one n1 where n1.name = n2.name)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.