group by - Ordering of grouped rows in mysql -
select t1.item_id, t1.item, t1.created, t1.owner, t1.type, t1.fld, t2.tag items t1 inner bring together tagged t2 on t1.item_id = t2.item_id tag in ('how', 'jkas', 'bodor', 'zimp', 'ctuo', 'sjex', 'kek' ) grouping item_id order t1.created desc limit 0 , 100
how order items how many matches have in tag? went deep in manual , couldn't find reply , got lost in stuff don't understand.
you can utilize count
, set results in subquery:
select * ( select t1.item_id, t1.item, t1.created, t1.owner, t1.type, t1.fld, t2.tag, count(distinct t2.tag) tagcount items t1 inner bring together tagged t2 on t1.item_id = t2.item_id tag in ('how', 'jkas', 'bodor', 'zimp', 'ctuo', 'sjex', 'kek') grouping item_id ) t order tagcount desc, created desc limit 0 , 100
mysql group-by sql-order-by
No comments:
Post a Comment