mysql - Sql join 3 tables -
i have struggle produce sql. relationship part of application. have 3 tables : users('id'), relationship('user_id', 'member_id'), relationship_block('user_id', 'blocked_member_id')
i members belonging user user_id not blocked.
records of first table 'users' in 'relationships' table not in 'relationship_blocked' table. first 2 can join, want remove blocked.
thanx.
edit: found info here: http://explainextended.com/2010/05/27/left-join-is-null-vs-not-in-vs-not-exists-nullable-columns/
select * users u inner join relationship r on u.user_id = r.user_id left join relationship_block rb on r.user_id = rb.user_id , r.member_id = rb.blocked_member_id rb.user_id null
Comments
Post a Comment