sql - Querying an indirect relationship -
i have app has users, libraries , books.
users have many libraries. libraries have many users , books. users , books not have direct relationship. users can borrow books libraries.
i'm stuck trying collection of books belongs libraries user member of. in other words, want of books in library given user belongs to.
to clear, don't want go through borrowing association exists between users , books, because want books in library, not ones borrowed user.
i've tried come query hours using sql , squeel, without luck... in advance help.
table_user user_id user_name library_id membership_id table_library library_id user_id book_id membership_id table_books books_id book_name library_id table_membership membership_id user_id library_id select book_name table_books inner join table_library on table_books.library_id=table_library.library_id inner join table_user on table_user.library_id=table_library.library_id table_user.library_id = table_membership.library_id , table_user.user_id =table_membership.user_id
Comments
Post a Comment