Mysql join from multiple tables

后端 未结 4 1975
半阙折子戏
半阙折子戏 2021-01-16 16:43

I have 3 tables

friends
posts
members

friends
========
id, to, from (user_id\'s), status

there are 3 status\'s -1 = denied, 0 = no response/new, 1 = accept         


        
4条回答
  •  借酒劲吻你
    2021-01-16 17:06

    Try this :

        SELECT p.text,m.f_name,m.l_name FROM posts p 
        LEFT OUTER JOIN members m ON p.user_id=m.member_id
        where p.user_id in(select id from friends);
    
    OR
    
       SELECT p.text,m.f_name,m.l_name FROM posts p 
       LEFT OUTER JOIN members m ON p.user_id=m.member_id
       INNER JOIN friends f on p.user_id=f.id
    

提交回复
热议问题