求助:查询两张表的不同记录(急)

foodchina_gx 2007-03-13 05:11:29
如下:
A表tbl_rfq_invite
intInviteId intRfqId intEntId dtDatetime
119 117 3877 2007-3-13 15:52:22 1
120 117 3878 2007-3-13 15:52:22 1
121 117 3879 2007-3-13 15:52:22 1
122 117 3880 2007-3-13 15:52:22 1
123 117 3881 2007-3-13 15:52:22 1
124 118 3877 2007-3-13 15:54:39 1
125 118 3878 2007-3-13 15:54:39 1
126 118 3879 2007-3-13 15:54:39 1
127 118 3880 2007-3-13 15:54:39 1
128 118 3881 2007-3-13 15:54:39 1

B表tbl_n_rfq_deposit
intDepId intRfqId intEntId dtDatetime
44 117 3881 2007-3-13 16:40:34 1
45 117 3880 2007-3-13 16:40:34 1
46 117 3879 2007-3-13 16:40:34 1

如何查询两表不相同的记录。
自己写的如下,有错误。intRfqId =117时返回两条记录,intRfqId =118时应该是五条记录,可是还是两条。
如下:
select * from tbl_rfq_invite
where intrfqid =117 and intenterpriseid not in
(SELECT b.intenterpriseid FROM tbl_n_rfq_deposit a INNER JOIN
tbl_rfq_invite b ON a.intRfqId = b.intRfqId
and a.intenterpriseid=b.intenterpriseid)

求大家帮助!急!
...全文
168 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
foodchina_gx 2007-03-13
  • 打赏
  • 举报
回复
感谢两位,我自己也想出个解决方案,不知道好不好,如下:
select * from tbl_rfq_invite
where intrfqid =117 and intinviteId not in
(SELECT intinviteId
FROM tbl_n_rfq_deposit a INNER JOIN
tbl_rfq_invite b ON a.intRfqId = b.intRfqId
and a.intenterpriseid=b.intenterpriseid
)
liuyinbo0109 2007-03-13
  • 打赏
  • 举报
回复
不好意思按错了
应该是:
select *
from tbl_rfq_invite A
where intrfqid =117 and intenterpriseid not exists
(SELECT 1
FROM tbl_n_rfq_deposit
where a.intRfqId = intRfqId and
a.intenterpriseid=intenterpriseid
)
paoluo 2007-03-13
  • 打赏
  • 举报
回复
try

Select * From tbl_rfq_invite A
Where intrfqid =117
And Not Exists (Select intRfqId, intenterpriseid From tbl_n_rfq_deposit Where intRfqId = A.intRfqId And intenterpriseid =A.intenterpriseid)
liuyinbo0109 2007-03-13
  • 打赏
  • 举报
回复
select *
from tbl_rfq_invite A
where intrfqid =117 and intenterpriseid not in
(SELECT b.intenterpriseid
FROM tbl_n_rfq_deposit a INNER JOIN
tbl_rfq_invite b ON a.intRfqId = b.intRfqId
and a.intenterpriseid=b.intenterpriseid)

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧