I'd create a clustered index on the file then use that index for your order by, but in the example below I used a (select 1) to sort as that is a trick to take the order it evaluates in a ranking function (I'd prefer the CLUSTER ID though even though results should be identical)declare @test table(id int PRIMARY KEY CLUSTERED (id) identity(1,1) ,studentnum int, studentscore int, studentage int)insert into @test(studentnum,studentscore,studentage)select 1122, 75, 18 union allselect 1122, 70, 18 union allselect 2233, 80, 20 union allselect 2233, 85, 20 union allselect 4455, 90, 19 union allselect 6565, 50, 19 union allselect 6565, 75, 19 union allselect 7777, 87, 18 union allselect 7777, 92, 18 select *from(select * ,ROW_NUMBER() over (partition by studentnum order by id) as rowidfrom @test ) aawhere aa.rowid =1 select *from(select * ,ROW_NUMBER() over (partition by studentnum order by (select 1)) as rowidfrom @test ) aawhere aa.rowid =1
Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881