View Single Post
  #1   IP: 58.241.198.25
Old 2012-12-06, 06:10 AM
topvip topvip is offline
超级版主
 
Join Date: 2006-01-04
Posts: 1206
topvip 正向着好的方向发展
Default 在mysql中如何用一个字段的值替换另一个字段的值

Q: 在同一个数据库中,先判断表A中的AID是否等于表B中的BID,如果是就用表A中的AC1的值去替换表B中的BC1的值。数据库为MYSQL,在PHPMYADMIN中操作,请问SQL命令该怎么写啊?

update b set bc1 = ( select ac1 from a where a.aid = b.bid)where exists (select 1 from ac1 where a.aid = b.bid)

==========================
update b set b.bid=a.ac1 where a.aid=b.bid
Reply With Quote