E
E
Egor Sh2016-04-07 17:04:04
MySQL
Egor Sh, 2016-04-07 17:04:04

How to generate sql query?

I have a Poll table, I have an Answer table, each record of which is associated with a poll by PollID, that is, the poll has several answers, and there is a Voice table that contains links to users in the User table (to know who voted) and to the answer is in the answer table. Here I need to check whether the current user voted in this poll. Please tell me how to create a request

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kovalsky, 2016-04-07
. @EgorkZe

do consecutive Join. But for this problem, you can do a little cropping

select г.userId from Ответ as o 
INNER JOIN Голос as г ON г.ОтветId = о.Id
WHERE o.Опросid = something AND г.UserId = something

If there is nothing in the sample, then the user did not vote.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question