|
|
|
|
![]() ![]() |
Apr 7 2007, 05:01 PM
Post
#1
|
|
|
Newbie [Level 1] ![]() Group: Members Posts: 12 Joined: 19-November 06 Member No.: 33,689 |
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 |
|
|
|
Apr 7 2007, 05:07 PM
Post
#2
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,077 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
Have a look here: http://dev.mysql.com/doc/refman/5.0/en/query-speed.html
|
|
|
|
Apr 7 2007, 05:11 PM
Post
#3
|
|
|
apt-get moo ![]() Group: [MODERATOR] Posts: 2,156 Joined: 28-May 05 From: Devon, England Member No.: 7,593 ![]() |
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.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 7th October 2008 - 09:51 PM |