簡體   English   中英

從一個表中查找不存在於另一個表中的記錄,以及從第三個表映射的用戶

[英]Find records from one table which don't exist in another & users mapped from third table

我是SQL的新手,請嘗試動手。

尋找一種有效的方法來獲取用戶表中存在但臨時表中不存在的用戶(*)

有三個表:

Temp:

member_no | name

User:

endUserId | name 

Login:

member_no | endUserId

我嘗試了這個但沒有用:

SELECT * 
FROM User LEFT OUTER JOIN
     Temp
      ON User.endUserId = (SELECT TOP 1 e.endUserId
                           FROM User e JOIN
                                LOGIN l
                                ON e.endUserId = l.endUserId 
                           WHERE l.username = Temp.member_no
                          )

提前致謝

如果您希望不處於臨時狀態的用戶not existsnot in not exists ,請注意:

select u.*
from user u
where not exists (select 1
                  from temp t join
                       login l
                       on t.memberno = l.memberno
                  where l.endUserId = u.endUserId
                 );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM