0

2つのテーブルがあります。

UserTable

userid   username
1        test
2        test2
3        test3


UserStatus

statusid userid status
1        1      1
2        1      3
3        1      7
4        2      1

ここで、ステータス3を持たないユーザーのユーザーリストが必要です。

何かアイデアはありますか?

4

4 に答える 4

3

あなたが使用することができますNOT EXISTS

select u.userid,
  u.username
from usertable u
where not exists (select s.userid
                  from userstatus s
                  where s.status = 3
                    and u.userid = s.userid);

SQL FiddlewithDemoを参照してください

于 2013-03-21T15:15:58.203 に答える
2

NOT INを使用できます:

SELECT usertable.*
FROM usertable
WHERE userid NOT IN (SELECT userid from userstatus where status=3)

こちらのフィドルをご覧ください。

于 2013-03-21T15:14:44.623 に答える
1
SELECT * FROM UserTable
WHERE userid NOT IN
(SELECT userid FROM UserStatus WHERE status = 3)
于 2013-03-21T15:15:54.273 に答える
1
SELECT username from UserTable
WHERE userid NOT IN (SELECT userid FROM UserStatus WHERE status = 3)
于 2013-03-21T15:15:08.967 に答える