Skip to content
Advertisement

Mysql query for finding followers and following

Here are the two tables:

Find follower of user: 2 Output should be:

I need a mysql query to find all the followers of a particular user with detail information of the followers from user table and need to know the number of followers each follower has and i also need to if the the particular user also following the follower. Here’s what I have tried:

I know I’m getting close ;). The problem is, I’m getting following with a yes value even though the user is not following back.Here is another weird thing – not all but some of them showing yes which should be no .Thanks!

Advertisement

Answer

Try this:

I tried it using the following data sets:

USER

1,a,abcd

2,b,bcde

3,c,cdef

user_follower

1,2,10

1,3,11

2,3,10

3,1,13

And got the expected result:

2,b,bcde,1,no

3,c,cdef,1,yes

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement