What is the general "best practice" for this type of functionality.
I have a table of users a table of polls and a table of poll responses on a website. I want to load a page that loads a poll that a user hasn't yet answer.
What is the most efficient and "best" way of going about this.
Things I've tried that seems slow/not optimal:
A query with nested selects using NOT IN
SELECT p.id
FROM poll p
WHERE p.id NOT IN (
SELECT r.pollID
FROM responses r
WHERE r.username = 'someuser'
)
A query that uses left joins
LEFT JOIN responses ON ( polls.id = responses.pollID
AND responses.username = 'someuser' )
WHERE
responses.username IS NULL
Both of these solutions seem to scale very poorly.
Other suggestions? Open to anything outside the box. (I.E. solutions that aren't confined to just different types of mysql queries)