首頁  >  文章  >  後端開發  >  如何在一张朋友表里面查询和自己有相同朋友并且不是自己的朋友的用户

如何在一张朋友表里面查询和自己有相同朋友并且不是自己的朋友的用户

WBOY
WBOY原創
2016-06-13 10:16:20878瀏覽

怎么在一张朋友表里面查询和自己有相同朋友并且不是自己的朋友的用户


uid和朋友ID都是在另外一张表里面
怎么在一张朋友表里面查询和自己有相同朋友并且不是自己的朋友的用户

------解决方案--------------------
朋友表friend中至少有两个字段,user_id字段和friend_id字段
1.首先查出自己的朋友:select friend_id from friend where user_id = "zhangshan";
2.select distinct user_id from friend where friend_id in (select friend_id from friend where user_id = "zhangshan") and user_id != "zhangshan" and user_id not in (select friend_id from friend where user_id = "zhangshan");

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn