Skip to content

Instantly share code, notes, and snippets.

@AbdallaZaki
Created April 11, 2017 21:47
Show Gist options
  • Save AbdallaZaki/430d841811941a4ceda19bdd45bf7c20 to your computer and use it in GitHub Desktop.
Save AbdallaZaki/430d841811941a4ceda19bdd45bf7c20 to your computer and use it in GitHub Desktop.
select tags.name , tags.id , count(taggables.id) as tags_ranks from taggables
join tags on taggables.tag_id = tags.id
join graphics on taggables.taggable_id = graphics.id
left outer join sub_categories on graphics.sub_category_id = sub_categories.id
left outer join categories on sub_categories.category_id = categories.id
where categories.id = 1 and taggables.taggable_type = 'Graphics'
group by tags.id order by tags_ranks DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment