作者neocc (neo)
看板Database
标题[SQL ] MSSQL 使用select from not in
时间Tue Mar 8 13:33:30 2016
资料库名称:MSSQL
资料库版本:MSSQL 2013
内容/问题描述:
各位好 我有两个表 都有自己的非Key 栏位 UID
A表
ID UID content1
-----------------
1 4 n1
2 5 n2
3 6 n3
4 7 n4
-----------------
B表
ID UID content2
----------------
2 6 n1
----------------
我想请教大家
SQL 要怎麽写 可以取得 UID 4, 5, 7呢? 这些数字在B表里面没有
而且我还需要把A表里面的这些UID 纪录删除
谢谢大家!~
--
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 219.71.221.131
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Database/M.1457415213.A.E89.html
1F:→ bohei: where not exists(select ....) 03/08 13:34
※ 编辑: neocc (219.71.221.131), 03/08/2016 13:47:04
2F:推 kb0130: Delete from a where not exists (select 1 from b where 03/09 10:11
3F:→ kb0130: A.uid=b.uid) 03/09 10:12