0

我有两张桌子,

CREATE TABLE [dbo].[entry]
(
   [id] [int] NULL,
   [service] [int] NULL,
   [sub] [int] NULL
) 

这些值是,

id     service  sub
1        1       0
2        1       1 
3        1       2 

第二张表是:

CREATE TABLE [dbo].[service]
(
   [service] [int] NULL,
   [sub] [int] NULL
) 

其值为:

service   sub
1          0
1          1

entry表中有 3 行,表service中有 2 行。我想要不在service表中但在entry表中的行

谢谢

文卡特

4

4 回答 4

1

尝试这个:

Select entry.id, temp.service, temp.sub from entry INNER JOIN 
(Select service, sub from entry 
Except
Select service, sub from service) as temp ON entry.service = temp.service AND entry.sub = temp.sub
于 2012-06-15T07:46:31.743 回答
0

解决问题的另一种方法

  Select a.id,a.service,a.sub from @entry as a where not EXISTS 
 (select b.* from @service as b where a.sub = b.sub and a.service=b.service)
于 2012-06-15T08:21:12.683 回答
0

使用 except 的代码的另一个变体。

select id, service, sub
from entry
except
select e.id, e.service, e.sub
from service as s left join entry as e
on s.service = e.service
and s.sub = e.sub
于 2012-06-15T13:22:49.727 回答
0
SELECT
    entry.id
  , entry.service
  , entry.sub
FROM
    entry
LEFT JOIN SERVICE ON entry.service = service.service AND entry.sub = service.sub
WHERE
    entry.service IS NULL
    AND entry.sub IS NULL
于 2012-06-15T14:14:55.277 回答