SQL语句,用于查找tbl1的唯一记录,而不包含同样存在于tbl2中的记录

SQL语句,用于查找tbl1的唯一记录,而不包含同样存在于tbl2中的记录,sql,Sql,我试图在“c”中列出记录,但这些记录也不属于“o”的一部分,但不知何故,我的代码无法基于customerNumber工作 select c.* from c where c.customerNumber not in (select o.customerNumber from orders o inner join customers c on c.customerN

我试图在“c”中列出记录,但这些记录也不属于“o”的一部分,但不知何故,我的代码无法基于customerNumber工作

select c.* 
from c 
where c.customerNumber not in (select o.customerNumber
                               from orders o 
                               inner join customers c on c.customerNumber = o.customerNumber);

我做错了什么?

您可以使用不存在的:

select c.* from c 
where not exists (
  select 1 
  from orders 
  where customerNumber = c.customerNumber
);
或者简化您的代码:

select  c.* from c 
where c.customerNumber not in (
  select  customerNumber
  from orders
);