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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajeev PunhaniRank #551 · 4.4K reputationPosted Mar 14, 2016, 12:44 AM EDT
Hi Surendra,
Please try this
If the above solution is helpful then,accept the answer.
Kunal PatelRank #1,359 · 1.2K reputationPosted Mar 13, 2016, 11:26 PM EDT
Pradip PandeyRank #452 · 5.6K reputationPosted Mar 11, 2016, 10:33 PM EST
Surendra Kumar35 reputationPosted Mar 12, 2016, 1:09 AM EST
Surendra Kumar35 reputationPosted Mar 13, 2016, 10:56 PM EDT
Surendra Kumar35 reputationPosted Mar 14, 2016, 12:08 AM EDT
ali tuncerRank #1,499 · 1.1K reputationPosted Mar 14, 2016, 12:17 AM EDT
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 Kumar35 reputationPosted Mar 14, 2016, 12:29 AM EDT
Kunal PatelRank #1,359 · 1.2K reputationPosted Mar 14, 2016, 1:04 AM EDT
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 Kumar35 reputationPosted Mar 14, 2016, 2:16 AM EDT
Surendra Kumar35 reputationPosted Mar 14, 2016, 2:16 AM EDT