Some background: I'm implementing a voting system using MySQL, with multiple polls being voted upon at any time. I have two tables: one called 'polls', which has an 'id' auto_inc field and a 'poll' string. Votes are held in the 'poll_votes' table; each vote record has an auto_inc 'id', a 'poll_id' int recording which poll the vote is for, and an 'address' string for the IP of the voter.
Here's the problem. I want to retrieve a list of those polls which the IP address in question has *not* voted upon. I can't figure out how to do this purely in SQL. It would be easy to 1) get a list of polls, and then 2) for each poll, check if the user has voted on that poll. But I'd like to just fire off a single SELECT and receive a list of 'poll' strings to do CGI junk with. I've never used joins before, so I'm having difficult wrapping my mind around the problem. Is it possible to do this with a single query?
Originally posted as a Categorized Question.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.