我对 MySQL 查询有点困惑:
我有表用户
user_id|language|name 1 |en |Mike 2 |en |John 3 |en |Jesse 4 |de |Wolfgang (Me)
和表users_blocked
user_id|blocked_user_id 1 |4 4 |1 1 |3 3 |1 4 |2
(其中 user_id 已阻止 blocked_user_id)
我想找到所有说英语 (en) 的用户(不包括我自己),我没有屏蔽他们,他们没有屏蔽我。 它应该只返回上面示例中 ID 为 3 的用户。
我正在构建一个语言合作伙伴搜索,它从结果中排除所有被阻止的用户(双向)。
最佳答案
来,试一试:
select * from users where user_id <> 4 and language = 'en'
and user_id not in(select blocked_user_id from users_blocked where user_id = 4)
and user_id not in(select user_id from users_blocked where blocked_user_id = 4)
关于MySQL - 从结果中排除所有被阻止的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19345689/