看板 Database 關於我們 聯絡資訊
資料庫名稱: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://www.ptt.cc/bbs/Database/M.1457415213.A.E89.html
bohei: where not exists(select ....) 03/08 13:34
※ 編輯: neocc (219.71.221.131), 03/08/2016 13:47:04
kb0130: Delete from a where not exists (select 1 from b where 03/09 10:11
kb0130: A.uid=b.uid) 03/09 10:12