Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Limiting Returned Data To Last X Fields With Sql
zeeman48
post 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
Go to the top of the page
 
+Quote Post
jlhaslip
post 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 Icon

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
Spam Patrol



Have a look here: http://dev.mysql.com/doc/refman/5.0/en/query-speed.html
Go to the top of the page
 
+Quote Post
rvalkass
post Apr 7 2007, 05:11 PM
Post #3


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,156
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Software To Restore Data(15)
  2. My Ipod Is Randomly Skipping Songs, Losing Data,(23)
  3. C Problem: "two Or More Data Types In Declaration"(6)
  4. New Tech: Data Transmiting At 2.56 Terabites Per Second!(11)
  5. Get 30 Gb Email For Free(31)
  6. Data Can Be Stored On Paper(31)
  7. How Good Is This Data Cleaning Function?(2)
  8. Data Base For A War Game(5)
  9. Data Recovery Software(3)
  10. Data Structures -- Linked List(9)
  11. Data Structures -- Linked List -- Reverse(5)
  12. Data Structures -- String -- Palindrome(5)
  13. Data Recovery Program..help!(6)
  14. Data Structure -- Queue -- Implement Using Stack(1)
  15. Free Web Hosting: (caius) [manual Data Input?] [denied](1)
  1. Treating .csv Files As Database Data(2)
  2. Data On My Subdomain/webspace Vanished(1)
  3. What Is The Best Software(5)
  4. What Value Would I Use To Insert This Data?(4)
  5. Tropical Stream And Wheat Fields(2)
  6. Getting Started With Mysql(2)
  7. Effective Search Over Web(0)
  8. Eraser - Erase Your Data Permanently! For Free(7)
  9. 1 Terabyte Of Data On A Thumb Drive(8)
  10. Very Disappointed With Data Center Migration(9)
  11. Need Help With My Database [resolved](6)
  12. Need Advice On Setting Up Mysql Database.(4)
  13. Create Dynamic Html/php Pages Using Simple Vb.net Code(1)


 



- Lo-Fi Version Time is now: 7th October 2008 - 09:51 PM