Hi I'm new to SQL and I'm trying to figure out how I'm going to get the top 5 "bands" with most friends (userId) and this is what i have; a usertbl with userId as PK then a bandsTbl with bandId as PK then I have a table bandfriends with FK userId and bandId.
bandfriends
userid | bandId
---------------
1 | 1
1 | 2
1 | 3
Thanks!
If you have friends table, bands table and a link table, works for me :)
Read up on COUNT and GROUP BY at mysql.org
You'll want something like this (I haven't tested it):
You can also optionally specify WITH TIES in the select statement. See this and this.