Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 1845 |  Welcome, Guest!   Register  Login
 Home > Forums > Sql Server > how to find last three value in table ...
Venky.Net

how to find last three value in table

Replies: 10 | Posted by: Venky.Net on 4/28/2012 | Category: Sql Server Forums | Views: 729 | Status: [Member] | Points: 10  


how to select last three value in table and suitable examle


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Gow.Net
Gow.Net  
Posted on: 4/28/2012 5:38:48 AM
Level: Starter | Status: [Member] | Points: 25

using BETWEEN and findout

gowthaman8870226416

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Niladri.Biswas
Niladri.Biswas  
Posted on: 4/30/2012 7:26:58 AM
Level: Diamond | Status: [Member] | Points: 25

Try this

Declare @t table(name varchar(100))

Insert Into @t
select 'abhijit' union all select 'debasis' union all select 'mangoli' union all select 'hobita' union all
select 'jansu' union all select 'uday' union all select 'santunu' union all select 'sachin' union all
select 'jeeva' union all select 'sashi'

Select Top 3 Name From(
Select
Rn = ROW_NUMBER() Over(Order by(Select 1) )
,Name
From @t
)x
Order By x.Rn desc


--Result
Name

sashi
jeeva
sachin


Best Regards,
Niladri Biswas

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Muhsinathk
Muhsinathk  
Posted on: 6/18/2012 7:28:28 AM
Level: Bronze | Status: [Member] | Points: 25


CREATE TABLE [dbo].[sample2](
[s_id] [int] IDENTITY(1,1) NOT NULL,
[s_Name] [varchar](10) NULL,
[s_Price] [int] NULL,
[s_product] [varchar](29) NULL,
PRIMARY KEY CLUSTERED
(
[s_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


SELECT TOP 3 * FROM sample2 ORDER by s_id DESC

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Nksingh420
Nksingh420  
Posted on: 6/18/2012 5:42:54 PM
Level: Starter | Status: [Member] | Points: 25

select top 3 * from books order by bid desc

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 6/19/2012 2:44:08 AM
Level: Silver | Status: [Member] | Points: 25

WITH employeeCTE AS

(
SELECT *,ROW_NUMBER()OVER(ORDER BY empid DESC) AS rowno FROM employee1
)

SELECT TOP 3 empid,empname FROM employeeCTE ORDER BY rowno



Table script



CREATE TABLE [dbo].[employee1](
[empid] [int] IDENTITY(1,1) NOT NULL,
[empname] [varchar](100) NULL,
PRIMARY KEY CLUSTERED
(
[empid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 6/19/2012 2:48:46 AM
Level: Silver | Status: [Member] | Points: 25



Insert Script

GO

SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[employee1] ON
INSERT [dbo].[employee1] ([empid], [empname]) VALUES (1, N'Pandian')
INSERT [dbo].[employee1] ([empid], [empname]) VALUES (2, N'Mani')
INSERT [dbo].[employee1] ([empid], [empname]) VALUES (3, N'Raj')
INSERT [dbo].[employee1] ([empid], [empname]) VALUES (4, N'Kv')
INSERT [dbo].[employee1] ([empid], [empname]) VALUES (5, N'Naveen')
SET IDENTITY_INSERT [dbo].[employee1] OFF

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Perfect.Chourasia@Gmail.Com
Perfect.Chourasia@Gmail.Com  
Posted on: 6/20/2012 3:06:12 AM
Level: Starter | Status: [Member] | Points: 25

select top 3 * from Table_Name order by Column_Name desc

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://sandeep-chourasia.blogspot.com/

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 6/20/2012 4:46:43 AM
Level: Silver | Status: [Member] | Points: 25

@Perfect.Chourasia@Gmail.Com
Question is to find-out the last 3 inserted value. Please check my answer.

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

CGN007
CGN007  
Posted on: 7/31/2012 10:04:32 AM
Level: Silver | Status: [Member] | Points: 25

please mark it as answer....That helps other who search the same...

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Ranjeet_8
Ranjeet_8  
Posted on: 7/31/2012 2:16:11 PM
Level: Gold | Status: [Member] | Points: 25

Select Top3 * From Table_Name Order by   Column_Name desc

Venky.Net, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/19/2013 5:27:07 PM