wompas.dub Posted July 15, 2008 Share Posted July 15, 2008 Hey everyone, I'm trying to figure out the most popular entries in a database. For example, if there are a ton of entries with the ID 2 I want it to figure out first how many entries have been made with that ID and then rank it by how many entries have that particular ID and then rank in order from greatest to least. I'm trying to figure out the queries I'd have to use but I'm not sure if there is some query I don't know about or if I'm going to have to do a series of queries and then process it with PHP. If anyone can point me in the right direction I'd appreciate it Quote Link to comment Share on other sites More sharing options...
discomatt Posted July 15, 2008 Share Posted July 15, 2008 Simple SELECT COUNT(*) as `total` FROM `table` GROUP BY `id` ORDER BY `id` DESC LIMIT 20 Quote Link to comment Share on other sites More sharing options...
wompas.dub Posted July 15, 2008 Author Share Posted July 15, 2008 I was doing something similar it kept giving me long repeated of the same number in no order at all. I'll try that out, thanks a lot Quote Link to comment Share on other sites More sharing options...
revraz Posted July 15, 2008 Share Posted July 15, 2008 Well if there are a ton of entries with ID 2, then you need something else to sort by. Quote Link to comment Share on other sites More sharing options...
discomatt Posted July 15, 2008 Share Posted July 15, 2008 Ooops, found a mistake in my query SELECT `id`, COUNT(*) as `total` FROM `table` GROUP BY `id` ORDER BY `total` DESC LIMIT 20 Quote Link to comment Share on other sites More sharing options...
wompas.dub Posted July 15, 2008 Author Share Posted July 15, 2008 nice discomatt, that was exactly what I needed. Strangely enough I have never needed to do anything like that before PM me if you ever need anything Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.