what I want is:

来源: 奉旨灌水 2013-03-05 20:07:37 [] [博客] [旧帖] [给我悄悄话] 本文已被阅读: 次 (479 bytes)
回答: 回复:问个SQL的问题new111!2013-03-05 19:55:37
if pk exists in both Table A and B, ignor record in Table B

if pk exist either in Table A or B, return it

think should union 3:

SELECT A.PK AS A_PK, A.Value AS A_Value FROM Table_A A INNER JOIN Table_B B ON A.PK = B.PK
UNION
SELECT A.PK AS A_PK, A.Value AS A_Value FROM Table_A A LEFT JOIN Table_B B ON A.PK = B.PK WHERE B.PK IS NULL
UNION
SELECT B.Value AS B_Value, B.PK AS B_PK FROM Table_A A RIGHT JOIN Table_B B ON A.PK = B.PK WHERE A.PK IS NULL

hope it works

所有跟帖: 

开始又不说清楚,哎 -令狐冲冲- 给 令狐冲冲 发送悄悄话 (0 bytes) () 03/05/2013 postreply 20:09:15

墨索里尼总是有理,过去有理,现在有理,而且将来永远有理 -奉旨灌水- 给 奉旨灌水 发送悄悄话 奉旨灌水 的博客首页 (87 bytes) () 03/05/2013 postreply 20:13:21

这啥呀? -令狐冲冲- 给 令狐冲冲 发送悄悄话 (0 bytes) () 03/05/2013 postreply 20:14:47

这句名言出自一部阿尔巴尼亚的电影,电影的名子是《宁死不屈》。 -奉旨灌水- 给 奉旨灌水 发送悄悄话 奉旨灌水 的博客首页 (320 bytes) () 03/05/2013 postreply 20:19:59

估计你的父母都不一定看过,嘿嘿 -奉旨灌水- 给 奉旨灌水 发送悄悄话 奉旨灌水 的博客首页 (4 bytes) () 03/05/2013 postreply 20:21:09

直接用not exists 不就行了?搞的这么复杂 -令狐冲冲- 给 令狐冲冲 发送悄悄话 (0 bytes) () 03/05/2013 postreply 20:13:46

how to deal exist? 不搞的这么复杂 -奉旨灌水- 给 奉旨灌水 发送悄悄话 奉旨灌水 的博客首页 (90 bytes) () 03/05/2013 postreply 20:15:54

回复:how to deal exist? 不搞的这么复杂 -令狐冲冲- 给 令狐冲冲 发送悄悄话 (230 bytes) () 03/05/2013 postreply 20:21:46

OK, I'll try. Thanks, vielen dank.Merci, תוד&# -奉旨灌水- 给 奉旨灌水 发送悄悄话 奉旨灌水 的博客首页 (0 bytes) () 03/05/2013 postreply 20:25:40

请您先登陆,再发跟帖!

发现Adblock插件

如要继续浏览
请支持本站 请务必在本站关闭/移除任何Adblock

关闭Adblock后 请点击

请参考如何关闭Adblock/Adblock plus

安装Adblock plus用户请点击浏览器图标
选择“Disable on www.wenxuecity.com”

安装Adblock用户请点击图标
选择“don't run on pages on this domain”