Click here to Skip to main content
15,919,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need a query for select last 5 maxkeys from my table.

I have one query but its returns only one value.

This is my query:
SELECT max(bkcrtkey) FROM bkcrtkts
Posted
Updated 3-Dec-10 4:10am
v2
Comments
Sandeep Mewara 2-Dec-10 10:51am    
Wo! 3 replies at the same time... same thing...
Corporal Agarn 2-Dec-10 11:59am    
In the future please use a title that is related to the problem.
Dalek Dave 3-Dec-10 10:11am    
Edited for Readability.

SELECT TOP 5 bkcrtkey FROM bkcrtkts ORDER BY bkcrtkey DESC
 
Share this answer
 
Comments
Sandeep Mewara 3-Dec-10 11:47am    
Agreed with what you said to other person replying half hour late.
+ a 5! from me for the answer which we posted together at same time! :)
Try,
SQL
SELECT 
   TOP 5 bkcrtkey 
FROM bkcrtkts 
ORDER BY bkcrtkey DESC
 
Share this answer
 
Comments
Sandeep Mewara 2-Dec-10 11:00am    
:)
Dalek Dave 3-Dec-10 10:11am    
Good Answer.
SELECT TOP 5 COLUMN_NAME FROM TABLE_NAME ORDER BY COLUMN_NAME SORTING_ORDER
 
Share this answer
 
v2
Comments
Dalek Dave 3-Dec-10 10:11am    
Good Call.
fjdiewornncalwe 3-Dec-10 11:26am    
sandipapatel. Copying the answers that others have given already is hardly an answer. Please read the other responses. If the answer has already been given, just add a comment stating that you agree with a given answer. If you look below, this is a unique case where 3 people gave the same answer in the same minute, but yours came half-an-hour later and was the same as the ones below. I'll give you the benefit of the doubt that you didn't read the others. But please, in the future, read those first before posting yours. Cheers.
This should work:
SELECT TOP 5 bkcrtkey FROM bkcrtkts ORDER BY bkcrtkey DESC
 
Share this answer
 
v2
Comments
sameertm 2-Dec-10 10:47am    
thanks alot
Dalek Dave 3-Dec-10 10:11am    
That'll Work.

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