Answer the question
In order to leave comments, you need to log in
How to select votes in which a specific user did not participate?
Good day to all.
Can't get into an elegant solution to the problem. I want to display for the user only those requests in which he did not accept voting.
There is a vote table, the backbone of the poll, and it has a one-to-many relationship with the vote_answer table.
The answer table in turn contains a one-to-many relationship with vote_result.
To get voted users, I make such a request with a comparison of the client's IP address.
SELECT *
FROM `poll`
INNER JOIN poll_answer ON poll.id = poll_answer.poll_id
INNER JOIN poll_result ON poll_answer.id = poll_result.poll_answer_id
WHERE CURDATE() BETWEEN poll.date_begin AND poll.date_end
AND poll_result.vote_ip ="222"
Answer the question
In order to leave comments, you need to log in
If we consider this as those polls where he took part
SELECT *
FROM `poll`
INNER JOIN poll_answer ON poll.id = poll_answer.poll_id
INNER JOIN poll_result ON poll_answer.id = poll_result.poll_answer_id
WHERE CURDATE() BETWEEN poll.date_begin AND poll.date_end
AND poll_result.vote_ip ="222"
SELECT *
FROM `poll` as b
WHERE NOT EXISTS (SELECT poll.id
FROM `poll`
INNER JOIN poll_answer ON poll.id = poll_answer.poll_id
INNER JOIN poll_result ON poll_answer.id = poll_result.poll_answer_id
WHERE CURDATE() BETWEEN poll.date_begin AND poll.date_end
AND poll_result.vote_ip ="222"
AND b.id = poll.id)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question