php - MYSQL table join deduct data -
i m building simplified social networking site in php. have 2 tables, myfriends table , friends table.
myfriends table has friend_id1 , friend_id2 columns. friends table has friend_id,profile_name , email columns.
the myfriends table links 2 friends together. assume uni directional relationship, instead of bidirectional. means friend_id1 has friend friend_id2 not vice versa.
to illustrate lets take 4 members 1001,1002,1003,1004
if 1001 knows 1002 , 1003 (and assuming vice versa) 1002, 1003 don’t know each other , 1004 not know anyone, myfriends table have following entries.
(1001,1002),(1001 ,1003),(1002 ,1001),(1003, 1001) i need query people not friends.this query have come friends.friend_id primary key of friends table.myfriends table doesnt have primary key.
select friends.profile_name friends inner join myfriends on friends.friend_id=myfriends.friend_id1 myfriends.friend_id2='$friendid'"; hope question clear all.
$sql="select profile_name friends
friend_id<>login_user_id
and
friend_id not in( select friend_id2 myfriends friend_id1=login_user_id);
Comments
Post a Comment