求助:查询两张表的不同记录(急)
如下:
A表tbl_rfq_invite
intInviteId intRfqId intEntId dtDatetime
11911738772007-3-13 15:52:221
12011738782007-3-13 15:52:221
12111738792007-3-13 15:52:221
12211738802007-3-13 15:52:221
12311738812007-3-13 15:52:221
12411838772007-3-13 15:54:391
12511838782007-3-13 15:54:391
12611838792007-3-13 15:54:391
12711838802007-3-13 15:54:391
12811838812007-3-13 15:54:391
B表tbl_n_rfq_deposit
intDepId intRfqId intEntId dtDatetime
4411738812007-3-13 16:40:341
4511738802007-3-13 16:40:341
4611738792007-3-13 16:40:341
如何查询两表不相同的记录。
自己写的如下,有错误。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)
求大家帮助!急!
[解决办法]
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)
[解决办法]
不好意思按错了
应该是:
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
)