sql - MYSQL filter by count of another table -
i'm beggining mysql. have following query:
select answers.data. * , count( answers.reports.id ) rcount answers.data left join answers.reports on answers.data.id = answers.reports.answer_id answers.data.question='4' group answers.data.id
it's returning me answers current question added column called rcount (number of reports)
i want return less 3 reports. tried following code:
select answers.data. * , count( answers.reports.id ) rcount answers.data left join answers.reports on answers.data.id = answers.reports.answer_id answers.data.question='4' , rcount < '3' group answers.data.id
but aprrently that's not new condition goes. can't find in manual solution since i'm new this. thanks
use having
clause:
select answers.data.* , count( answers.reports.id ) rcount answers.data left join answers.reports on answers.data.id = answers.reports.answer_id answers.data.question='4' group answers.data.id having count( answers.reports.id ) < 3
Comments
Post a Comment