Jump to content

SQL Group BY error


houssam_ballout

Recommended Posts

hello all,

I am trying this sql:

select count(OptionNb),comments from tblanswer where idQuestion = $idQuestion And OptionNb = 'option$i'

and I got this error

Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

 

How could I solve it ?

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/91654-sql-group-by-error/
Share on other sites

you may want to review: http://dev.mysql.com/doc/refman/5.0/en/counting-rows.html

 

 

im not sure what exact reslults your trying to get and what your table structure is but you could try this:

 

select count(OptionNb),comments from tblanswer where idQuestion = $idQuestion And OptionNb = 'option$i'  GROUP BY `comments`

Link to comment
https://forums.phpfreaks.com/topic/91654-sql-group-by-error/#findComment-469478
Share on other sites

I'm curious to know what information you're trying to get out of this.

On 1st inspection I thought you were after the number of comments for a particular question, however I then realised you appear to be after something related to OptionNB. What is OptionNB?

 

The query that uniflare has given you will count the number of options based on comment, where the question id is set and the OptionNB is set.

 

Clarify what you're expecting from this query and i'm sure we can guide you in the right direction.

Link to comment
https://forums.phpfreaks.com/topic/91654-sql-group-by-error/#findComment-469487
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.