Shahsays
Shahsays

Reputation: 431

mysql query to select rows based on count

i have this database

enter image description here

i want to select options_e if it has options less than 4, or something like this

SELECT * FROM `options` WHERE count(qid) <4 

so that it will return the result of options who are less than 4. but on phpmyadmin when i run the query, it says invalid use of group function. why do I get this error? who can i fix this?

Upvotes: 2

Views: 1326

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172438

You can try like this:

SELECT options_e, options_f, options_p, options_a, options_s  FROM `options`
GROUP BY options_e, options_f, options_p, options_a, options_s
HAVING count(qid) < 4

Upvotes: 2

Related Questions