如何获取不在另一个表SQL Server 2005中退出的数据 [英] how to get the data that does not exits in another table sql server 2005
问题描述
你好朋友
我想获取不在另一个表中退出的数据
例如.假设我有两个表A和B,其中包含
表A表B
srprefix srno前缀no
pp/10 1 pp/10 1
pp/10 2 pp/10 2
pp/10 3 pp/10 3
pp/09 3
请帮助我如何获得未在表A中退出的输出
同时检查前缀和无字段
即pp/09 3
我使用了join,但无法正常运行
感谢u
Hello Friends
I want to get the data that does not exits in another table
eg. suppose i have two table A and B which contains
Table A Table B
srprefix srno prefix no
pp/10 1 pp/10 1
pp/10 2 pp/10 2
pp/10 3 pp/10 3
pp/09 3
pls help me how could i get the output which does not exits in Table A
checking both the prefix and no fields
i.e pp/09 3
i used join but it does not work properly
Thank u
推荐答案
如果srno和没有列的内容相同,以下查询将解决问题:
The following query does the trick if the srno and no columns have the same content:
select * from B where no NOT IN (SELECT srno from A)
对此的快速解决方案是:
A quick solution for that would be:
select * from B where no+''''+prefix NOT IN (SELECT srno+''''+srprefix from A)
注意:我没有对此进行测试.因此,您可能会遇到一些错误(并且可能还可以删除''串联)
NOTE: I did not test this. So you might get some errors (and probably you can also remove the '''' concatenation)
确定问题已解决
我使用了除了关键字
-表购买CHALLAN
SELECT chln_prefix,chln_no
从PC
除
--TABLE购买帐单
SELECT前缀,doc_no
FROM PB
OK THE PROBLEM IS SOLVED
I USED EXCEPT KEYWORD
--TABLE PURCHASE CHALLAN
SELECT chln_prefix,chln_no
FROM PC
EXCEPT
--TABLE PURCHASE BILL
SELECT prefix,doc_no
FROM PB
这篇关于如何获取不在另一个表SQL Server 2005中退出的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!