Click here to Skip to main content
15,867,851 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends


How can Select Only last Row of the Table Using Sql
Posted

Use IDENTITY COLUMN in your database. If you don't have one,add it to existing table.Then proceed as follows:
C#
Select TOP 1 * from your_table ORDER BY identity_column DESC

Regards..
 
Share this answer
 
Comments
Nandakishore G N 18-Oct-13 5:14am    
good answer...My 5
Thanks7872 18-Oct-13 5:15am    
Thanks :-)
SQL
SELECT * FROM(SELECT rownum nbr, t.* FROM dept t order by deptno)

where nbr>(select count(*)-1 from dept)
 
Share this answer
 
 
Share this answer
 
Try the following code. . .
SQL
DECLARE @MYVAR NVARCHAR(100)
Declare @MyVar2 nvarchar(100)
DECLARE MYTESTCURSOR CURSOR
DYNAMIC 
FOR
SELECT EmpID,EmpName FROM Employees
OPEN MYTESTCURSOR
FETCH LAST FROM MYTESTCURSOR INTO @MYVAR,@MyVar2
CLOSE MYTESTCURSOR
DEALLOCATE MYTESTCURSOR
SELECT @MYVAR,@MyVar2
 
Share this answer
 
this is your answer ...
SQL
Select TOP (1) * from yourTable ORDER BY primaryKEyColumn DESC
 
Share this answer
 
v2

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