Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想向服务器创建 mysql 请求,我想从表中检索我在朋友列表中没有的用户。
这是我正在尝试学习的方法,但我没有收到请帮助我
SELECT t1.*, t2.* FROM users as t1, friends as t2 WHERE t2.user_id='1' and t2.fr_id!=t1.id ORDER BY RAND()
您想要的查询类似于:
SELECT t1.*, t2.* FROM users t1 left outer join friends t2 on t2.fr_id = t1.id and t2.user_id = '1' WHERE t2.user_id is null ORDER BY RAND();
我不确定t2.user_id = 1它在做什么。如果您正在查看整个朋友列表,则不需要它。
t2.user_id = 1