php - Correct SQL Query for Accessing Groups available to User -


i have series of tables set in following way (they have been simplified readability):

user - id - name  user_has_oi_relationship - user_id - oi_relationship_id  oi_relationship - id - description  chat_group_has_oi_relationship - chat_group_id - oi_relationship_id  chat_group - id - name - description 

each entry in 'user' table has series of oi relationships attached it, defined in 'user_has_oi_relationship' table. each chat group has series of oi relationships attached it, defined in 'chat_group_has_oi_relationship' table.

what i'd select available chat groups available particular user, defined user id, based on oi relationships.

i'm pretty joins , such, 1 stumping me. keep getting groups returned!

i think should it:

select cg.* chat_group cg join chat_group_has_oi_relationship cgr on cg.id = cgr.chat_group_id join user_has_oi_relationship ur on ur.oi_relationship_id = cgr.oi_relationship_id join user u on ur.user_id = u.id u.name = 'john smith' 

if not, please make sqlfiddle sample data.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -