首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

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

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

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


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");

热点排行