V
V
vostotskiy2017-09-09 22:21:58
MySQL
vostotskiy, 2017-09-09 22:21:58

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"

Tell me, please, in which direction to dig.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Holub, 2017-09-09
@vostotskiy

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"

Those where he did not accept:
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)

O
oh, 2017-09-09
well @AnneSmith

IP is probably not very reliable
, can it be easier to store request id in cookies?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question