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

mysql and joins

Options
  • 11-03-2004 4:22pm
    #1
    Subscribers Posts: 1,911 ✭✭✭


    I have three tables:
    users (user_id, username)
    classlists (user_id, module_id)
    submissions (user_id, module_id, assignment_id, submission_id)

    I am trying to get an end result where I have a table of all the users in a module and their submission for an assignment. If there is no submission, I want nulls instead.
    ie
    user_id | module_id | assignment_id | submission_id
    1 | 1 | 1 | 1
    2 | 1 | 1 | 2
    3 | 1 | null | null

    I'm using the following query:
    SELECT * FROM 
    (classlists INNER JOIN users ON (classlists.user_id = users.user_id))
     LEFT JOIN 
    submissions ON (users.user_id = submissions.user_id) 
    WHERE
     (assignment_id = 1 OR assignment_id IS NULL) AND classlists.module_id = 1
    

    Instead of getting what I want above, I am just getting rows with all the info in them.

    am I going the right direction? or just barking up the wrong tree?


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    try this

    Select sub.* From
    classLists cs Left outer join submissions sub on (cs.userid =sub.userid)
    or am I missing something ?

    the other thing is in classlists you should really have a ClassListsID and use that in the submissions table (normalisation and all that jazz)


Advertisement