Current location: Hot Scripts Forums » Other Discussions » Database » ASP- SQL Server..Query help....


ASP- SQL Server..Query help....

Reply
  #1 (permalink)  
Old 01-31-07, 12:19 AM
cancer10 cancer10 is offline
Wannabe Coder
 
Join Date: Oct 2006
Location: India
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Question ASP- SQL Server..Query help....

Hello,

I am using ASP and MS SQL Sever 2000 as backend database..

I am writing a SQL query which will pick up top 5 recipes details who have scored the highest marks from the following table

tblrecipes -

Code:
 ID |  recipe_name | Total
The following points to be noted:

- The table has 500 records.
- 50 of them have achieved the highest marks ie 100 marks each
- My following query is picking up top 5 records who have scored 100 marks

Code:
SELECT TOP 5 ID, total, recipe_name
FROM tblrecipes 
ORDER BY total DESC
and getting this output:

http://img2.freeimagehosting.net/uploads/3d14a5272a.jpg


Now my question is:

On what basis its showing up this sequence of listing? I mean why the ID 89 is on the top and 136 at the bottom? Why the ID is not the other way round?

Like the following?

ID
__
178
136
89
286
340


Can someone explain please?


Thanx
Reply With Quote
  #2 (permalink)  
Old 01-31-07, 04:02 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
This is probably something for the database section.

Anyway, I think that if there's multiple rows that could be in the Top5, then MS SQL takes random row? Totally unsure if this is true or not

If you want to have more control over the output, try defining more fields in your ORDER BY clause..
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
  #3 (permalink)  
Old 01-31-07, 04:07 AM
cancer10 cancer10 is offline
Wannabe Coder
 
Join Date: Oct 2006
Location: India
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Vicious

If you want to have more control over the output, try defining more fields in your ORDER BY clause..

for example?
Reply With Quote
  #4 (permalink)  
Old 01-31-07, 06:11 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
ORDER BY field1 ASC, field2 ASC, field3 DESC

...
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sql Query Help - ASP cancer10 ASP 4 05-06-10 06:12 PM
How to do SQL query in a ASP while loop superman2004 ASP 2 09-09-04 03:35 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 04:57 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.