MySQL query problem
Posted
by FinalDestiny
on Stack Overflow
See other posts from Stack Overflow
or by FinalDestiny
Published on 2010-04-01T08:51:38Z
Indexed on
2010/04/01
8:53 UTC
Read the original article
Hit count: 182
mysql
I have 2 mysql tables
1. questions: with the following columns: id, title, answer1, answer2, answer3, answer4, answer5, nranswers.
and
2. answers with the following columns: id, questionid, userid, answer
Every question has maximum 5 answers( it can have between 2 and 5 answers). My problem is that I want to select from my database, for a given question, how many times was every option selected.
For example, let's suppose I have the question with the id 46, with 4 answers, and 48 users voted for the option #2, 37 users for the option #1 and 39 for the option #4.
I want a query that selects that and write these things:
1 37 2 48 3 0 4 39
P.S. VERY IMPORTANT! IT MUST COUNT ONLY NRANSWERS ANSWERS, AND IT MUST ECHO THE ONES THAT WEREN'T VOTED BEFORE.
© Stack Overflow or respective owner