SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)

    SELECT where one table has no record...

    I am trying to select all of the values in one table that do not exsist in another.

    The first table (section) looks like:
    Code:
    section_id | section_name | survey_id
    The second table (page_user) looks like:
    Code:
    page_num | page_complete | participant_id
    What I am trying to do is select the section_ids from the section table where the section_id does not have an equal value in page_num. page_num only gets set when a user completes a page so if they have not completed page 5 there is no 5 for page_num under the page_user table. However, there is a section_id 5 and I am trying to get those, where section_id = 5 but page_num hasn't been set.

    Any help would be greatly appreciated.

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I will give it a shot. Try the following:

    Code:
    SELECT s.section_id FROM section as s
      LEFT JOIN page_user as p ON p.page_num = s.section_id
    WHERE p.page_num IS NULL
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    The only problem I have with that is that I need a specific participantID and a specific survey_id as well...

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You should be able to add that to your query without any major hazzle.

    Code:
    SELECT s.section_id, p.participant_id FROM section as s
      LEFT JOIN page_user as p ON p.page_num = s.section_id
        AND p.participant_id = 'a specific id'
    WHERE s.section_id = 5 AND p.page_num IS NULL
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •