Create table
USE [Test] GO /****** Object: Table [dbo].[Test_order] Script Date: 06/05/2013 10:21:16 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Test_order]( [TID] [int] IDENTITY(1,1) NOT NULL, [RID] [int] NULL, [Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] GO SET ANSI_PADDING OFF
then insert lines
insert into dbo.Test_order values(1,'Test1') insert into dbo.Test_order values(3,'Test3') insert into dbo.Test_order values(2,'Test2') insert into dbo.Test_order values(5,'Test5') insert into dbo.Test_order values(6,'Test6') insert into dbo.Test_order values(4,'Test4') insert into dbo.Test_order values(9,'Test9') insert into dbo.Test_order values(7,'Test7') insert into dbo.Test_order values(8,'Test8')
this request will order data according to RID
select distinct b.TID,b.RID,b.[Name] from dbo.Test_order as a,dbo.Test_order as b where a.RID>=b.RID
source share