Page 1 of 1

ordering

Posted: Thu May 05, 2005 6:40 am
by thesimon
sorry if this is a database question, however i am not exactely sure if the solution is in the php or the mysql query itself.

I have a table that stores hits to press releases

ie: (Key | TimeDate | IP Address | Press Release ID)

Now i need to group by (press release id), and then count how many rows share each (press release id), then order the records in a table by the amount of rows in the database table per Press Release,

In other words i want to show the 5 Most popular press releases on the page.

pre-emtive thanks

Posted: Thu May 05, 2005 12:00 pm
by Stryks
You should be able to get the results with something fairly simple.

A query along the lines of ...

Code: Select all

SELECT `Release_ID`, count(`Release_ID`) AS `rank` FROM `tbl_hits` GROUP BY `Release_ID` ORDER BY `rank` DESC LIMIT 5
... should do the trick if you simply want the top 5 release ID's.

You could link these results back to the press release table if you want to pull back titles or other info.

Maybe this should be moved to databases. 8)