SQL存在一個表而不在另一個表中的資料,sql不在

來源:互聯網
上載者:User

SQL存在一個表而不在另一個表中的資料,sql不在

select a.id,a.oacode,a.custid,a.custname,a.xsz,a.salename,a.communicationtheme,a.communicationproperty,a.communicationtime,a.productmanager,'' creator,a.creator oaCreator,a.createdate,case when a.oastate='正常結束' then 3 else 0 end status from reception_flow a where  (1=1)and (a.oastate='正常結束' or a.oastate='反饋中' or a.oastate='已反饋')and (select count(1) as num from technology_support s where s.oacode=a.oacode)=0


怎用sql語句查詢:在一個表中存在而另一個表中不存在的第一條記錄?

select top 1 *
from tb2
where id not in (select [index] from tb1)
order by id
 
sql查詢一個表裡的資料在另一個表是否存在

insert into tableA
select * from tableB b where not exists(select 1 from tableA a where a.id = b.id)
insert into tableA
select * from tableB b
left join tableA a on a.id = b.id
where a.id is null
----用 not exists來判斷,left join ,其中條件為唯一性主鍵
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.