sql - Select two records where a two way relationship exists -


i have user table contains user id , name.

i have likes table contains userid1 , userid2.

when user1 likes user2, ids entered in likes table respectively.

how can retrieve users both each other?

join likes table , select rows mutual likes:

    select *        likes like1  inner join likes like2 on like1.userid1 = like2.userid2                        , like1.userid2 = like2.userid1 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -