Added "order by", "limit", and "having" to "group by" query