我们有 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 的用户。
有什么想法吗?
最佳答案
您可以使用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);
关于mysql - sql加入where和1-n连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15551314/