Not sure if this is possible - but I am trying to do the following Have a table with following colums
vote_id (primary_key)
question_id
user_id
vote_count
This basically stores all the votes casted by users for a particular question
Now in a single query is it possible for me to get the total vote count and check if a particular user has casted his vote or not.
Something along these lines - lets say for user_id 10
SELECT sum(vote),
(
CASE
WHEN (user_id = 10)
THEN user_id
ELSE NULL
END
) user_id
FROM vote_question
GROUP BY course_question_id
This obviously doesn't work.
What I'm expecting is if a particular user has voted - his user_id should be returned along with vote count - if he not voted - return null
Thanks