I want Last Five Record from table. Condition is Column contains duplicate and null values.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajeev PunhaniPosted Mar 14, 2016, 4:44 AM
Hi Surendra,
Please try this
If the above solution is helpful then,accept the answer.
Surendra KumarPosted Mar 14, 2016, 6:16 AM
Surendra KumarPosted Mar 14, 2016, 6:16 AM
Kunal PatelPosted Mar 14, 2016, 5:04 AM
WITH Student_CTE (Id,Stu_Id, Student_Name, City,Registered)
AS
(
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS Id,Stu_Id, Student_Name, City,Registered FROM Student
)
SELECT TOP(5) Id,Stu_Id, Student_Name, City,Registered FROM Student_CTE ORDER BY Student_CTE.Id desc;
Surendra KumarPosted Mar 14, 2016, 4:29 AM
ali tuncerPosted Mar 14, 2016, 4:17 AM
if you add primary key(ID) and set auto-increment, you can write like this :
Select s.Stu_Id,s.Student_Name,s.City
from
(
Select top 5 Stu_Id,Student_Name,City,ID
from dbo.Student
order by ID desc) as s
order by s.ID
Surendra KumarPosted Mar 14, 2016, 4:08 AM
Kunal PatelPosted Mar 14, 2016, 3:26 AM
Surendra KumarPosted Mar 14, 2016, 2:56 AM
Surendra KumarPosted Mar 12, 2016, 6:09 AM
Pradip PandeyPosted Mar 12, 2016, 3:33 AM