请看一下这个查询,并尝试给我任何其他可以更有效地给出完全相同结果的想法。
SELECT username
FROM users
WHERE username NOT IN (
SELECT DISTINCT username
FROM users, friends
WHERE 'user1' IN (you,friend,username)
AND you IN ('user1',username)
AND friend IN ('user1',username))
AND username <> 'user1'