Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello to all.

I have 50 records in database. I have to display top 10 records at run-time.
Now when i add new record it comes at no. 51.
I want that it comes under 10, so that i can display top 10 records from data base. Or if there is any other way to display it then please tell me.
Posted
Updated 5-Jul-10 20:04pm
v2
Comments
Sandeep Mewara 6-Jul-10 2:05am    
What is the logic you want to be in Top10? last 10 inserted records? Suddenly, out of blues a new record cannot come into top 10, there should be some criteria you must be following to fetch top 10. What is it?
HanuBaba 6-Jul-10 2:12am    
see i have various items like tv of electronics, neckless of accessories, books of stationery.
now suppose 1 have already 50 records in the database..nw i add one record of elect., one of accessories and one of stationery.
now these records are coming at no. 51, 52,53
now how will it come at under 10.. because at page load i will have to display top10 records from the database.

use order by in your query

use this.

SQL
Select top 10 ProductId , ProductName from Products order by productId desc


Hope this helps
 
Share this answer
 
Comments
Lalit Kumar 5733 6-Jul-10 3:07am    
Reason for my vote of 5
gud answer
Balaji Sathe 6-Jul-10 3:15am    
Reason for my vote of 5
good and simple answer..
you can also order by date added

as:

Select top 10 ProductId , ProductName from Products order by dateAdded desc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900