SQL join help for friend list

后端 未结 4 1204
猫巷女王i
猫巷女王i 2021-01-18 18:41

I have three database tables: users, user_profiles and friends:

users

  • id
  • username
4条回答
  •  醉梦人生
    2021-01-18 19:10

    Some modification to eugene y's answer, will this work?

    SELECT * FROM users u
    JOIN friends f ON (f.userb_id = u.id OR f.usera_id = u.id)
    JOIN user_profiles p ON u.id = p.user_id
    WHERE u.id = ?
    

提交回复
热议问题