I have similar to StackExchange network that utilises tagged questions.
In my web application Users also can find
tags. The query below returns a set of tagged questions:
SELECT question.*, user_activity.* FROM question JOIN user_activity ON ua_id = qs_id JOIN question_tag ON qt_question_id = qs_id JOIN tag ON qt_tag_id = tag_id WHERE tag_name IN (:tags) GROUP BY qs_id HAVING count(tag_id) >= :tagCount
:tags is array of tag names and
:tagCount == count for this array.
In my opinion this query has bad practice even though it does things right.
Are there any ways to optimise this query?