php - Sorting SQL results from two tables -


i have 2 tables, tags , coupon_tags. tags contains tagname , tagid. each unique name has unique id. perhaps tag foo may have tagid 1, example.

then coupon_tags has bunch of couponid's , bunch of tagid's. there 1 row per coupon per tag. coupon may, of course, have more 1 tag. table may this:

tagid | couponid   5        3   4        3   9        3   5        6 

what i'm trying top 10 most-used tags. i've no experience in sorting algos or heavy sql i'm not sure @ how begin. help?

do this:

 select tagid, count(*) totaloccurrences coupon_tags     group tagid     order totaloccurrences desc     limit 10 

this give used tags ids.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -