If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Help with a query in join clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-03-06, 07:19
rexselin rexselin is offline
Registered User
 
Join Date: Aug 2003
Location: India
Posts: 109
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?
Reply With Quote
  #2 (permalink)  
Old 06-03-06, 17:26
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
select poll_name 
  from polls 
left 
  join responses 
    on responses.response_id = polls.poll_id
   and responses.user_id = 937
 where responses.response_id is null
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On