SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

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 ASP Free Forums Sponsor:
  #1  
Old October 30th, 2003, 01:09 PM
coderock coderock is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 3 coderock User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Have you heard of SELECT TOP 10 * ?

In looking for a way to show only the top 10 records by date I found this. If you look at the code the record counting does the limt work. But why do they have "TOP 10 *" instead of just *. Does it serve a purpose?

URL

mySQL = "SELECT TOP 10 * FROM tblScripts ORDER BY DateEntered DESC"

Reply With Quote
  #2  
Old October 30th, 2003, 01:26 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Quote:
mySQL = "SELECT TOP 10 * FROM tblScripts ORDER BY DateEntered DESC"

It only returns the first 10 records and orders them by the DateEntered field. The TOP ?? only selects the first ?? records that match the query.

If you just wanted to return the first 10 records from a database where the state was equal to "Missouri" you would write the query like this
Code:
SELECT TOP 10 * FROM tableName WHERE state = 'Missouri'

Reply With Quote
  #3  
Old October 30th, 2003, 01:43 PM
coderock coderock is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 3 coderock User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks

I guess the record count part was what was throwing me off . I just went and commented all that out and sure enough the top with a number works all alone. Not sure why that source would put the record count code in there too?

Learn something new every hour it seems.
Thanks again

Reply With Quote
  #4  
Old January 10th, 2004, 07:23 PM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
Can you do SELECT 10 to 20 * FROM table etc.?

I'd want to select the second grouping of 10 records from the database.

Reply With Quote
  #5  
Old January 11th, 2004, 01:25 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
no, you would have to do a .move statement to select the next 10 records...basically the way db paging is done.

Reply With Quote
  #6  
Old January 11th, 2004, 01:38 AM
shamrog12's Avatar
shamrog12 shamrog12 is offline
Newton's Apple Wizard
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 1,661 shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level)shamrog12 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Weeks 2 Days 2 h 39 m 22 sec
Reputation Power: 34
Send a message via AIM to shamrog12
I never use Access but rather MySQL. Is there an equivalent to Access's .move?

Reply With Quote
  #7  
Old February 10th, 2004, 03:02 PM
telemere telemere is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 5 telemere User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Where do you put this code? before the recordset? I am using an access database. Will it work there? My query brings up 1784 responses and access can't handle that. I want to bring up the first 50 and then be able to click next and so on. Like with ebay when you look up guitar it brings up a lot of results and they are broken apart into many pages. Can you help me? make that happen?



Quote:
Originally Posted by Memnoch
It only returns the first 10 records and orders them by the DateEntered field. The TOP ?? only selects the first ?? records that match the query.

If you just wanted to return the first 10 records from a database where the state was equal to "Missouri" you would write the query like this
Code:
SELECT TOP 10 * FROM tableName WHERE state = 'Missouri'

Reply With Quote
  #8  
Old February 10th, 2004, 08:43 PM
telemere telemere is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 5 telemere User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Where does the code go.

OK but where do you put it? Right before the recordset function?

Quote:
Originally Posted by telemere
Where do you put this code? before the recordset? I am using an access database. Will it work there? My query brings up 1784 responses and access can't handle that. I want to bring up the first 50 and then be able to click next and so on. Like with ebay when you look up guitar it brings up a lot of results and they are broken apart into many pages. Can you help me? make that happen?

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Have you heard of SELECT TOP 10 * ?


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
Stay green...Green IT