April 29, 2010 at 10:23 pm
how to retrieve last 5 records from emp table?
April 29, 2010 at 10:58 pm
Sri, sorry for saying this, but your question is one of the vaguest i have seen in my stint with SSC..
There is absolutely no information about the emp table in your post, but you have thrown a frisbee to us to find something..:doze:..
You know, the amount you put to guess a solution will be the same for us too..Hmmm..
Anyways, assuming your emp table has a column called EMPID and it is a INT/BIGINT/SMALLINT column, here is how you retrive the last 5 rows
SELECT TOP 5 * FROM EMP ORDER BY EMPID DESC
Hope this helps you!
Cheers!
April 29, 2010 at 11:01 pm
When posting questions, be sure to post more and detailed information in order for us to assist you faster and better.
Do you have an ID column? or any column with computed numbers in a specific order?
It could even be datetime stamps?
If you have a column like that, try:
Select top 5 * from emp
order by ?column? DESC
Note: this is not the best way to do this query, but given the limited info, this is a basic "retrieve last 5 records" query.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle
April 30, 2010 at 9:24 pm
Homework, Test, or Interview?
--Jeff Moden
Change is inevitable... Change for the better is not.
April 30, 2010 at 9:26 pm
ColdCoffee (4/29/2010)
Sri, sorry for saying this, but your question is one of the vaguest i have seen in my stint with SSC..There is absolutely no information about the emp table in your post, but you have thrown a frisbee to us to find something..:doze:..
You know, the amount you put to guess a solution will be the same for us too..Hmmm..
Anyways, assuming your emp table has a column called EMPID and it is a INT/BIGINT/SMALLINT column, here is how you retrive the last 5 rows
SELECT TOP 5 * FROM EMP ORDER BY EMPID DESC
Hope this helps you!
Cheers!
Heh... I dunno CC... looks like you did alright. 😉 In fact, you've probably just helped someone graduate. 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
May 3, 2010 at 12:09 am
Jeff Moden (4/30/2010)
ColdCoffee (4/29/2010)
Sri, sorry for saying this, but your question is one of the vaguest i have seen in my stint with SSC..There is absolutely no information about the emp table in your post, but you have thrown a frisbee to us to find something..:doze:..
You know, the amount you put to guess a solution will be the same for us too..Hmmm..
Anyways, assuming your emp table has a column called EMPID and it is a INT/BIGINT/SMALLINT column, here is how you retrive the last 5 rows
SELECT TOP 5 * FROM EMP ORDER BY EMPID DESC
Hope this helps you!
Cheers!
Heh... I dunno CC... looks like you did alright. 😉 In fact, you've probably just helped someone graduate. 😛
😛 thanks Jeff! No sound from the OP, guess he/she is still finalizing on the schemas :-D!
May 3, 2010 at 1:50 am
Hi
You can also use RowNumber, if you know the number of rows of data see
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply