Jump to content
xisto Community
Sign in to follow this  
zeeman48

Limiting Returned Data To Last X Fields With Sql

Recommended Posts

Hello, I'm currently developing a social-networking site in ColdFusion and several aspects of the site require me to return a limited number of records for display (e.g. displaying the last 3 news items in the left-hand column on the front page, etc.).I currently only have a small SQL "cheet sheet" and what my ColdFusion reference book tells me, and I cannot find anything anywhere about limiting the data returned from a SELECT statement to the last X number of records.Any help is appreciated!Thanks,zeeman48

Share this post


Link to post
Share on other sites

The simplest way is to just tag LIMIT = X onto the end of your query, with X representing the number of rows you want to return. However, this will return them in the order they appear in the database. Normally you want to include a statement in the SQL command to order the data according to a set column. For the news example here, order them by descending for the date or time column, then limit the query to 3 results.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.