Lux Interior
Lux Interior

Reputation: 321

Getting count from complicated mysql statement

I'm trying to get the count of unique questions from the following mysql statement but every time I try to add count(q.id) as questionCount the statement only returns one result. I'm obviously doing something wrong but I can't figure out what it is.

http://www.sqlfiddle.com/#!2/34906/58

Hope somebody can help.

Steve

Upvotes: 1

Views: 64

Answers (2)

DRapp
DRapp

Reputation: 48139

It appears you want the total questions "stamped" on every row... for example you are auto-generating a test and want it to show "Out of 5 questions" in the output. To simplify this, since you KNOW you want 5 questions via your WHERE clause, I would slightly adjust it to...

select
      FinalQA.*
   from
      ( select 
              5 as TotalQuestionsOffered,
              QWithAllAnswers.*,
              ... rest of query ) FinalQA
   where
      FinalQA.ARankSeq <= FinalQA.TotalQuestionsOffered

Upvotes: 0

Just edit 2nd line of your query to this one:

select
  count(distinct FinalQA.QUESTION_ID)   from.....

Upvotes: 1

Related Questions