SELECT TOP WITH TIES

create table tie 
( 
    id int, 
    price int 
) 
insert into tie values (1, 20); 
insert into tie values (1, 30); 
insert into tie values (1, 40); 
insert into tie values (1, 50); 
insert into tie values (1, 60); 
insert into tie values (1, 60);

select top 5 with ties from tie 
order by price asc; 

Results
1 20
2 30
3 40
4 50
5 60
6 60
The first 6 rows are part of the result set. 6 rows because row number 5 and 6 have the same price value. The price value is looked at because the WITH TIES clause has an ORDER BY on price. An order by clause is mandatory with the WITH TIES construct.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *