User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 423,464 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,836 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 1662 | Replies: 1
Reply
Join Date: Dec 2004
Location: India
Posts: 234
Reputation: cancer10 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
cancer10's Avatar
cancer10 cancer10 is offline Offline
Posting Whiz in Training

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

  #1  
Jan 31st, 2007
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 -

 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

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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Location: Plymouth, UK
Posts: 79
Reputation: msaqib is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
msaqib msaqib is offline Offline
Junior Poster in Training

Re: ASP- SQL Server..Query help....

  #2  
Feb 2nd, 2007
Try
SELECT TOP 5 ID, total, recipe_name
FROM tblrecipes 
ORDER BY total DESC, ID DESC

The thing is that you haven't manetioned to sort the ID colums as well. So IDs appear in the order of last modified data/time.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP Forum

All times are GMT -4. The time now is 3:12 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC