MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 16th, 2000, 05:26 AM
Sidane Sidane is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 28 Sidane User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 47 m 40 sec
Reputation Power: 0
Firstly I'm new to MySQL & PHP, secondly this topic was partially covered elsewhere but my question wasn't answered (so please don't flame me )

I've got a DB for news with DateTime as the Primary Key. On the homepage I have the 7 newest story headlines displayed, with a brief 2 line synopsis and link to the full story.

I have all this working fine using:
SELECT date, headline, synopsis FROM story ORDER BY date DESC

I then loop through the first 7 results. However I'm wondering just how efficient this is. The table is small at the moment but will get bigger and bigger with potentially 1000s of stories. What kind of performance hit can I expect as the DB grows?

I also have another table for feature stories which does exactly the same thing on the homepage, ie display 3 newest features.

Is there a more efficient way of doing this, something like explicitly selecting the last 7 rows ordered by date, without having to select every row in the table?

Thanks in advance for any advice/help.

[This message has been edited by Sidane (edited June 16, 2000).]

Reply With Quote
  #2  
Old June 16th, 2000, 07:06 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
Limit the result to 7 or however many you want.

SELECT date, headline, synopsis FROM story ORDER BY date DESC limit 7

Reply With Quote
  #3  
Old June 16th, 2000, 07:37 AM
Sidane Sidane is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 28 Sidane User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 47 m 40 sec
Reputation Power: 0
Would somebody please tell me why I didn't think of that in the first place!!

I'm sure I tried that and something went wrong. But it works fine now. Cheers.

What about the performance issue of searching through ever record in the table? Does the LIMIT parameter avoid this?

Reply With Quote
  #4  
Old June 16th, 2000, 11:39 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
No, because MySQL still has to read all the records to order them. It does save on your script processing time and system memory.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Selecting newest rows from a Table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway