Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Join Question

Status
Not open for further replies.

Faithfulman

Programmer
Jan 3, 2005
4
US
I am having issues here. I really am lossed on this one.

Similar to a earlier post but different:


TABLE poll_qs
pollId
....
...
..


TABLE poll_ans
pollAId - ID FOR THIS POLL
pollId - ID FOR poll_qs POLL
....
...

TABLE users
userId
firstName
lastName
....
...


I want to user to view how many polls he has not voted on and it to automatically come up with the next poll he needs to vote on. The below only shows me what he has voted on:

Code:
SELECT poll_qs.pollId, poll_ans.pollAId, users.firstName, users.lastName FROM poll_qs LEFT OUTER JOIN poll_ans ON poll_ans.pollId = poll_qs.pollId LEFT OUTER JOIN users ON poll_ans.userId = users.userId WHERE users.userId = '1'

So for example, I have 6 polls, and have voted on 5 of them. With the above query, I can see 5 poll answers with my name on them ... but I don't get the poll that I haven't voted on. I would like to see the poll that I haven't voted on and everything else show up as NULL.


Does anyone have any help for me?

Thanks in Advance!

Faithful
 
Maybe this ?
SELECT poll_qs.pollId, poll_ans.pollAId, users.firstName, users.lastName FROM poll_qs LEFT OUTER JOIN poll_ans ON poll_ans.pollId = poll_qs.pollId AND poll_ans.userId = '1' LEFT OUTER JOIN users ON poll_ans.userId = users.userId

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV, you are just too cool. Thank you so much!

God Bless,
Faithful
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top