Skip to content Skip to sidebar Skip to footer

Mysql Fetch Users Who Are Not Yet Friends

Hello guys I'm new to this, I need your help to fetch users who are not yet friends. This is my tables: Users id username 1 kyle 2 jane 3 jim 4 c

Solution 1:

select a.username 
  from users a 
   left join friends b 
      on a.username= b.username 
        where b.username is null;

Also, a simple better approach would be:

user table

userid  username
1       kyle
2       jane
3       jim
4       carla

friends table

friendid  userid  friend
1          1       jane
2          2       kyle
3          1       jim
4          3       kyle

Post a Comment for "Mysql Fetch Users Who Are Not Yet Friends"