求助:查询两张表的不同记录(急)
如下:
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)
求大家帮助!急!
------解决方案--------------------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
)