TOP 5

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

TOP 5

Post by vchris »

I want to display the 5 records with the highest "clickcount" value.

I want to display the 5 most recent records. I have a "dateadded" field.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have a look into the ORDER BY clause
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

I know there was a TOP function in SQL but I don't know if it still works with MySQL.

I've tried to search for it but got nothing on the mysql site. I'd rather have the query only get 5 records instead of all.
User avatar
shoebappa
Forum Contributor
Posts: 158
Joined: Mon Jul 11, 2005 9:14 pm
Location: Norfolk, VA

Post by shoebappa »

Add LIMIT to feyd's recommendation.
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Post by vchris »

Thanks works perfectly! :D
Post Reply