<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TOP WITH TIES &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/top-with-ties/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 04 Oct 2017 07:19:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server: The Awesome TOP clause WITH TIES option</title>
		<link>https://www.dbrnd.com/2016/02/sql-server-the-awesome-top-clause-with-ties-option/</link>
					<comments>https://www.dbrnd.com/2016/02/sql-server-the-awesome-top-clause-with-ties-option/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 29 Feb 2016 20:00:15 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TOP]]></category>
		<category><![CDATA[TOP WITH TIES]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1610</guid>

					<description><![CDATA[The SQL Server TOP clause WITH TIES option is not a new feature, but still many of database developers don&#8217;t know about it. This option is available with the TOP clause since a long time, and this is one of the best TSQL options. We are using the TOP clause to a SELECT TOP N [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fsql-server-the-awesome-top-clause-with-ties-option%2F&amp;linkname=SQL%20Server%3A%20The%20Awesome%20TOP%20clause%20WITH%20TIES%20option" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fsql-server-the-awesome-top-clause-with-ties-option%2F&amp;linkname=SQL%20Server%3A%20The%20Awesome%20TOP%20clause%20WITH%20TIES%20option" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fsql-server-the-awesome-top-clause-with-ties-option%2F&amp;linkname=SQL%20Server%3A%20The%20Awesome%20TOP%20clause%20WITH%20TIES%20option" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fsql-server-the-awesome-top-clause-with-ties-option%2F&amp;linkname=SQL%20Server%3A%20The%20Awesome%20TOP%20clause%20WITH%20TIES%20option" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fsql-server-the-awesome-top-clause-with-ties-option%2F&amp;linkname=SQL%20Server%3A%20The%20Awesome%20TOP%20clause%20WITH%20TIES%20option" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fsql-server-the-awesome-top-clause-with-ties-option%2F&amp;linkname=SQL%20Server%3A%20The%20Awesome%20TOP%20clause%20WITH%20TIES%20option" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fsql-server-the-awesome-top-clause-with-ties-option%2F&#038;title=SQL%20Server%3A%20The%20Awesome%20TOP%20clause%20WITH%20TIES%20option" data-a2a-url="https://www.dbrnd.com/2016/02/sql-server-the-awesome-top-clause-with-ties-option/" data-a2a-title="SQL Server: The Awesome TOP clause WITH TIES option"></a></p><p>The SQL Server TOP clause WITH TIES option is not a new feature, but still many of database developers don&#8217;t know about it.  </p>
<p>This option is available with the TOP clause since a long time, and this is one of the best TSQL options. </p>
<blockquote><p>We are using 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. </p></blockquote>
<p>The TOP WITH TIES option works based on a defined column in the ORDER BY clause.</p>
<p><strong>Below is a small demonstration of TOP WITH TIES clause:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestTOPClause
(
	EmpID INT IDENTITY(1,1)
	,EmpName VARCHAR(50)
	,Age INT
	,DepartmentName VARCHAR(50)
	,CONSTRAINT pk_tbl_TestTOPClause_EmpID PRIMARY KEY(EmpID)
)
GO

INSERT INTO tbl_TestTOPClause
(EmpName,Age,DepartmentName)
VALUES
('Anvesh',28,'Production')
,('Neevan',20,'Sales')
,('Jenny',21,'Account')
,('Jenny',24,'Production')
,('Martin',25,'Inventory')
,('Ruhan',30,'Sales')
,('Peter',33,'Account')
,('Peter',26,'Production')
,('Peter',23,'Inventory')
GO</pre> </p>
<p><strong>SELECT TOP records with out WITH TIES option:</strong></p>
<pre class="crayon-plain-tag">SELECT TOP 3 * 
FROM tbl_TestTOPClause 
ORDER BY EmpName DESC
GO

--The Result:

EmpID       EmpName        Age         DepartmentName
----------- ---------- ----------- ----------------------
6           Ruhan          30          Sales
7           Peter          33          Account
8           Peter          26          Production</pre> </p>
<p><strong>SELECT TOP records using WITH TIES option using EmpName in ORDER BY:</strong></p>
<pre class="crayon-plain-tag">SELECT TOP 3 WITH TIES *
FROM tbl_TestTOPClause 
ORDER BY EmpName DESC
GO

--The Result: Return 4 records because Empname = Peter is a duplicate three times.
EmpID       EmpName          Age         DepartmentName
----------- ----------- ----------- ------------------------
6           Ruhan            30          Sales
7           Peter            33          Account
8           Peter            26          Production
9           Peter            23          Inventory</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/02/sql-server-the-awesome-top-clause-with-ties-option/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
