help how to show relation data

i’ve problem in displaying data from 1 table

uid | Follower |

1 | 2 |

1 | 3 |

4 | 2 |

2 | 4 |

In this case, uid 2 has follow uid 1 and 4
but only uid 4 has following back uid 2, and the uid 1 not following uid 2
the problem is, i’ve no idea how to show uid that doesn’t following back the uid that following him in one select query :frowning:

I love little puzzles like this…

Anyway here’s your answer, of course you’ll have to change “TableName” to whatever matches your TableName.

SELECT follows as This_User, uid as Does_Not_Follow_Back  FROM TableName A where not exists (select 1 from TableName B where A.uid = b.follows and a.follows = b.uid)

The results are

This_User | Does_Not_Follow_Back
2 | 1
3 | 1

woahhh thank you so much, its almost done, i amaze it can be done in one query…

i try and it works for all uid in table, the really problem is how to know who is not following uid 2 in where clause, i try…

SELECT 
follows as This_User, 
uid as Does_Not_Follow_Back  FROM TableName A 
where not exists 
(select 1 from TableName B where A.uid = b.follows and a.follows = b.uid) 
AND A.uid = 2

its zero result… :’(


its DONE XD XD thank you so muchhh Topcoder

this is it

SELECT 
follows as This_User, 
uid as Does_Not_Follow_Back  FROM TableName A 
where not exists 
(select 1 from TableName B where A.uid = b.follows and a.follows = b.uid) 
AND follows = 2

Glad you got it working…

Sponsor our Newsletter | Privacy Policy | Terms of Service