共同好友SQL with Join(Mysql)

共同好友SQL with Join(Mysql),第1张

共同好友SQL with Join(Mysql)
SELECt id, nameFROM usersWHERe id IN (  SELECt friend_id  FROM user_relationships  WHERe user_id IN ( 1, 2 )  GROUP BY friend_id  HAVINg COUNT(friend_id) >= 2)

或一次连接

SELECt friend_id, nameFROM user_relationships r  INNER JOIN users u ON r.friend_id = u.idWHERe user_id IN ( 1, 2 )GROUP BY friend_idHAVINg COUNT(friend_id) >= 2


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4911071.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存