从[表格]中选择*,其中列不在(空)中

时间:2018-11-05 09:15:07

标签: sql

我正在执行此查询

select CardId, CardHeader from [Card] 
where CardId not in (select CardId from RoleMap where RoleId = 2)

(select CardId from RoleMap where RoleId = 2)的输出为null

并且输出受到0行影响

3 个答案:

答案 0 :(得分:2)

您可以尝试使用左联接

select CardId, CardHeader from [Card] a left join RoleMap b on a.CardId =b.CardId 
and RoleId = 2
where b.cardid is not null

答案 1 :(得分:1)

尝试一下:

SELECT CardId, CardHeader 
FROM   [Card] 
WHERE  CardId NOT IN (SELECT ISNULL(CardId, 0) from RoleMap WHERE RoleId = 2)

答案 2 :(得分:0)

不存在

select t.* from [Card] t
where  not exists (select 1 from RoleMap t1 where RoleId = 2
                                     and t1.CardId=t.CardId)