name, street, city, state, zip
bill, 123 main, newcity, null, 77777
bill, 123 main, newcity, null, 77777
fred, 23 west, greattown, null, 12345
bob, 4 a St, nowhere, null, 34567
表B中
name, street, city, st, zip
bill, 123 main, newcity, me, 77777
bill, 123 main, newcity, me, 77777
fred, 23 west, greattown, ny, 12345
bob, 4 a St, nowhere, wy, 34567
我想要做的
update table A
set state = tB.st
from
table A tA inner join table B tB
on (tA.name = tB.name and tA.street = tB.street)
,但我不想更新2条记录“法案,123主要,newcity,null,77777“。
如何从表中排除这些行?
感谢 查尔斯
什么是你的DBMS? SQL Server或Oracle或MySQL? – 2012-03-01 22:05:27
表A上是否有一些使重复记录不同的id字段? – 2012-03-01 22:08:01
您可以在UPDATE语句结尾处的“AND NOT EXISTS(SELECT name FROM A WHERE name = tB.name)”一行中找到。 – 2012-03-01 22:15:36