Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2003

    Unanswered: Help with a query in join clause

    Hi all,

    I have to do a two table join where in I want a list of rows from TABLE1 whose IDs do not appear in TABLE2.

    I checked quite a few sites before I found this query.
    Select table1.ID from table1 left join table2 on table1.value=table2.value
    where table2.value is null

    but my table structure is a little complex and this query doesn't work for me.
    I have a polls table which has all polls and a responses table where all users responses are getting stored. At a point of time, I would need to find out those polls which are unanswered by one particular user.

    So, my query is

    select poll_name from polls left join responses on polls.poll_id=responses.response_id where responses.response_id is null

    but this wont work as the responses table has user_id which records not only the concerned user but also the other users responses.

    How do I do this?

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    select poll_name 
      from polls 
      join responses 
        on responses.response_id = polls.poll_id
       and responses.user_id = 937
     where responses.response_id is null | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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