在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
|