SQL Server: The Awesome TOP clause WITH TIES option

The SQL Server TOP clause WITH TIES option is not a new feature, but still many of database professionals don’t know about it.

This option is available with the TOP clause since long time and this is one of the my best TSQL options.

Generally, we use the TOP clause to a SELECT TOP N number of records from a Table, but using TOP WITH TIES option we can also include the duplicate or same value of records in the result.

The TOP WITH TIES option works based on defined column in the ORDER BY clause and SELECT duplicate data for that column.
We can not use TOP WITH TIES option with ORDER BY clause.

Below is a small demonstration of TOP WITH TIES clause:

SELECT TOP records with out WITH TIES option:

SELECT TOP records using WITH TIES option using EmpName in ORDER BY:

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

Be the First to Comment!

Notify of