如何比较sql中2个diff表中的2个cols [英] how to compare 2 cols in 2 diff tables in sql
本文介绍了如何比较sql中2个diff表中的2个cols的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
i正在sql server 2008上工作。
我正在比较一个列从一个到另一个表,
彼此不相等。
n
我的查询,我到目前为止尝试的是:
SELECT COUNT(i.ITMRQ)as vCount FROM tbl_itmrq i
内部联接tbl_po p on p.Itmrq!= i.ITMRQ
请告诉我这个是否正确或不是。
谢谢
解决方案
使用不存在:
SELECT COUNT(i.ITMRQ) as vCount FROM tbl_itmrq i
WHERE NOT EXISTS
( SELECT * FROM tbl_po p <跨度cl ass =code-keyword> WHERE p.Itmrq = i.ITMRQ)
参考: sql-exists [ ^ ]
Hi guys,
i was working on sql server 2008.
where i was comparing a column from one to another table,
which is not equal to one another.
n
my query, what i tried so far, is:
SELECT COUNT(i.ITMRQ) as vCount FROM tbl_itmrq i inner join tbl_po p on p.Itmrq != i.ITMRQ
plz let me know, whether this one is correct or not.
thanks
解决方案
use not exists instead:
SELECT COUNT(i.ITMRQ) as vCount FROM tbl_itmrq i WHERE NOT EXISTS (SELECT * FROM tbl_po p WHERE p.Itmrq = i.ITMRQ)
refer: sql-exists[^]
这篇关于如何比较sql中2个diff表中的2个cols的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文