Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL cartesian problem

  • 04-05-2012 2:14pm
    #1
    Registered Users, Registered Users 2 Posts: 7,838 ✭✭✭


    I've got a left outer join query returning a cartesian product and I can't see where the problem is. Can you have a look please?
    SELECT username, loan_date, copy_id, book_title 
    FROM members m 
    LEFT OUTER JOIN membership_card mc ON m.mem_id = mc.mem_id 
    LEFT OUTER JOIN loans l ON l.mem_id = mc.mem_id 
    LEFT OUTER JOIN book_copies bc ON l.isbn = bc.isbn 
    LEFT OUTER JOIN books b ON b.isbn = bc.isbn;
    

    Will provide ERD screenshot in a sec


Comments

  • Registered Users, Registered Users 2 Posts: 7,838 ✭✭✭Nulty


    It just clicked :rolleyes:
    SELECT username, loan_date, copy_id, book_title 
    FROM members m 
    LEFT OUTER JOIN membership_card mc ON m.mem_id = mc.mem_id 
    LEFT OUTER JOIN loans l ON l.mem_id = mc.mem_id 
    LEFT OUTER JOIN book_copies bc ON l.isbn = bc.isbn AND bc.copy_id = l.copy_id 
    LEFT OUTER JOIN books b ON b.isbn = bc.isbn;
    

    The loans table has two foreign keys in book copies fields, I needed to specify the join on both keys.


Advertisement