使用除了在sql中查找某些行

时间:2017-02-15 15:40:27

标签: sql-server sql-server-2008

我试图从一张桌子中找到他们在另一张桌子上没有相应记录的行。

    <h1 id="header"> List King </h1>
<h2> Buy grocceries </h2>
<ul>
  <li id="one" class="hot"> Fresh </li>
  <li id="two" class="hot"> Fresh 1</li>
  <li id="three" class="hot"> Fresh 2 </li>
   <li id="one" class="cool"> Fresh </li>
  <li id="two" class="cool"> Fresh 1</li>
  <li id="three" class="cool"> Fresh 2 </li>
 </ul>

问题是SQL不喜欢不匹配的列数。如何获取缺失的行和相关信息?

1 个答案:

答案 0 :(得分:1)

select 
* from data t1
where not exists(select 1 from applications a where a.cust_number=t1.cust_number)


;With cte
as
(
select cust_number from data
except 
select cust_number applications 
)
select * from data where cust_number in (select cust_number from cte)