I have created a sample example. Hope this may help you. declare @tbl table(firstname varchar(50),lastname varchar(50)) insert into @tbl select 'firstname' + CONVERT(varchar(50),column_id) ,'lastname' + CONVERT(varchar(50),column_id) from sys.columns select * from @tbl
select firstname,lastname from
(select ROW_NUMBER() over(order by firstname) as rn,firstname,lastname
from
(
select
distinct(firstname),lastname
from @tbl t
)X(firstname,lastname))Y(rn,firstname,lastname)
where rn between 0 and 0 + 6 -1
As per the understanding I made after going thru ur statement, I thought that u r looking for unique records. Henceforth, in the very beginning only I have used a distinct clause. Note:- I tried to explain the concept. You need to customise and implement as per ur requirement. Let me know in case of any concern. I cannot make out why instead of using 5 directly u are using 0+6-1? :)
Niladri Biswas