<?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>sql quiz &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/sql-quiz/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>Sun, 17 Jun 2018 20:16:58 +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 Puzzle: Get the last three Records of a table</title>
		<link>https://www.dbrnd.com/2018/07/sql-puzzle-get-the-last-three-records-of-a-table/</link>
					<comments>https://www.dbrnd.com/2018/07/sql-puzzle-get-the-last-three-records-of-a-table/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 16 Jul 2018 16:16:29 +0000</pubDate>
				<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[SQL Advance Query]]></category>
		<category><![CDATA[sql commands]]></category>
		<category><![CDATA[SQL Interview]]></category>
		<category><![CDATA[SQL Problem]]></category>
		<category><![CDATA[SQL Programming]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[sql quiz]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[sqlcode]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7661</guid>

					<description><![CDATA[Check the below input data and expected output to get the last three records of a table. Input Data: [crayon-6aa8671313680751245185/] Expected Output: [crayon-6aa8671313687848240742/] Create a sample table: [crayon-6aa8671313688015749021/] Solution: [crayon-6aa8671313689715428129/] Please try the different solution for this puzzle and share it via comment...]]></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%2F2018%2F07%2Fsql-puzzle-get-the-last-three-records-of-a-table%2F&amp;linkname=SQL%20Puzzle%3A%20Get%20the%20last%20three%20Records%20of%20a%20table" 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%2F2018%2F07%2Fsql-puzzle-get-the-last-three-records-of-a-table%2F&amp;linkname=SQL%20Puzzle%3A%20Get%20the%20last%20three%20Records%20of%20a%20table" 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%2F2018%2F07%2Fsql-puzzle-get-the-last-three-records-of-a-table%2F&amp;linkname=SQL%20Puzzle%3A%20Get%20the%20last%20three%20Records%20of%20a%20table" 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%2F2018%2F07%2Fsql-puzzle-get-the-last-three-records-of-a-table%2F&amp;linkname=SQL%20Puzzle%3A%20Get%20the%20last%20three%20Records%20of%20a%20table" 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%2F2018%2F07%2Fsql-puzzle-get-the-last-three-records-of-a-table%2F&amp;linkname=SQL%20Puzzle%3A%20Get%20the%20last%20three%20Records%20of%20a%20table" 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%2F2018%2F07%2Fsql-puzzle-get-the-last-three-records-of-a-table%2F&amp;linkname=SQL%20Puzzle%3A%20Get%20the%20last%20three%20Records%20of%20a%20table" 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%2F2018%2F07%2Fsql-puzzle-get-the-last-three-records-of-a-table%2F&#038;title=SQL%20Puzzle%3A%20Get%20the%20last%20three%20Records%20of%20a%20table" data-a2a-url="https://www.dbrnd.com/2018/07/sql-puzzle-get-the-last-three-records-of-a-table/" data-a2a-title="SQL Puzzle: Get the last three Records of a table"></a></p><p>Check the below input data and expected output to get the last three records of a table. </p>
<p><strong>Input Data:</strong></p>
<pre class="crayon-plain-tag">ID          Name
----------- ----------
1           ABC
2           XYZ
3           ERZ
4           HYU
5           BNM
6           WER
7           WER
8           CVC
9           ASD</pre> </p>
<p><strong>Expected Output:</strong></p>
<pre class="crayon-plain-tag">ID          Name
----------- ----------
7           WER
8           CVC
9           ASD</pre> </p>
<p><strong>Create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestTable (ID INT, Name VARCHAR(10))

INSERT INTO tbl_TestTable 
VALUES (1,'ABC'),(2,'XYZ'),(3,'ERZ')
,(4,'HYU'),(5,'BNM'),(6,'WER')
,(7,'WER'),(8,'CVC'),(9,'ASD')</pre> </p>
<p><strong>Solution:</strong></p>
<pre class="crayon-plain-tag">;WITH CTE AS
(
	SELECT TOP (SELECT COUNT(1)-3 FROM tbl_TestTable) ID 
	FROM tbl_TestTable  
)
SELECT *  FROM tbl_TestTable 
WHERE ID NOT IN (SELECT ID FROM CTE)</pre> </p>
<p><strong><code>Please try the different solution for this puzzle and share it via comment...</code></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/07/sql-puzzle-get-the-last-three-records-of-a-table/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Puzzle: Delete Duplicate Data without Primary key, ROW_NUMBER()</title>
		<link>https://www.dbrnd.com/2018/06/sql-puzzle-delete-duplicate-data-without-primary-key-row_number/</link>
					<comments>https://www.dbrnd.com/2018/06/sql-puzzle-delete-duplicate-data-without-primary-key-row_number/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 04 Jun 2018 16:16:21 +0000</pubDate>
				<category><![CDATA[SQL Puzzle]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[SQL Advance Query]]></category>
		<category><![CDATA[sql commands]]></category>
		<category><![CDATA[SQL Interview]]></category>
		<category><![CDATA[SQL Problem]]></category>
		<category><![CDATA[SQL Programming]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[sql quiz]]></category>
		<category><![CDATA[SQL Tips and Tricks]]></category>
		<category><![CDATA[sqlcode]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7665</guid>

					<description><![CDATA[Check the below input data and expected output for deleting the duplicate data by giving an ID. The table doesn&#8217;t have any primary key and writes logic without using ROW_NUMBER(). Input Data: [crayon-6aa8671315724093499312/] Expected Output: [crayon-6aa8671315728832702455/] Create a sample table: [crayon-6aa8671315729163432782/] Solution: [crayon-6aa867131572a299398929/] Please try the different solution for this puzzle and share it via [&#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%2F2018%2F06%2Fsql-puzzle-delete-duplicate-data-without-primary-key-row_number%2F&amp;linkname=SQL%20Puzzle%3A%20Delete%20Duplicate%20Data%20without%20Primary%20key%2C%20ROW_NUMBER%28%29" 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%2F2018%2F06%2Fsql-puzzle-delete-duplicate-data-without-primary-key-row_number%2F&amp;linkname=SQL%20Puzzle%3A%20Delete%20Duplicate%20Data%20without%20Primary%20key%2C%20ROW_NUMBER%28%29" 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%2F2018%2F06%2Fsql-puzzle-delete-duplicate-data-without-primary-key-row_number%2F&amp;linkname=SQL%20Puzzle%3A%20Delete%20Duplicate%20Data%20without%20Primary%20key%2C%20ROW_NUMBER%28%29" 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%2F2018%2F06%2Fsql-puzzle-delete-duplicate-data-without-primary-key-row_number%2F&amp;linkname=SQL%20Puzzle%3A%20Delete%20Duplicate%20Data%20without%20Primary%20key%2C%20ROW_NUMBER%28%29" 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%2F2018%2F06%2Fsql-puzzle-delete-duplicate-data-without-primary-key-row_number%2F&amp;linkname=SQL%20Puzzle%3A%20Delete%20Duplicate%20Data%20without%20Primary%20key%2C%20ROW_NUMBER%28%29" 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%2F2018%2F06%2Fsql-puzzle-delete-duplicate-data-without-primary-key-row_number%2F&amp;linkname=SQL%20Puzzle%3A%20Delete%20Duplicate%20Data%20without%20Primary%20key%2C%20ROW_NUMBER%28%29" 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%2F2018%2F06%2Fsql-puzzle-delete-duplicate-data-without-primary-key-row_number%2F&#038;title=SQL%20Puzzle%3A%20Delete%20Duplicate%20Data%20without%20Primary%20key%2C%20ROW_NUMBER%28%29" data-a2a-url="https://www.dbrnd.com/2018/06/sql-puzzle-delete-duplicate-data-without-primary-key-row_number/" data-a2a-title="SQL Puzzle: Delete Duplicate Data without Primary key, ROW_NUMBER()"></a></p><p>Check the below input data and expected output for deleting the duplicate data by giving an ID. The table doesn&#8217;t have any primary key and writes logic without using ROW_NUMBER().</p>
<p><strong>Input Data:</strong></p>
<pre class="crayon-plain-tag">ID          Name
----------- ----------
1           ABC
1           ABC
1           ABC
3           ERZ
3           ERZ
4           HYU
5           BNM
7           WER
7           WER</pre> </p>
<p><strong>Expected Output:</strong></p>
<pre class="crayon-plain-tag">ID          Name
----------- ----------
1           ABC
3           ERZ
3           ERZ
4           HYU
5           BNM
7           WER
7           WER</pre> </p>
<p><strong>Create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestTable (ID INT, Name VARCHAR(10))

INSERT INTO tbl_TestTable 
VALUES (1,'ABC'),(1,'ABC'),(3,'ERZ')
,(4,'HYU'),(5,'BNM'),(1,'ABC')
,(7,'WER'),(3,'ERZ'),(7,'WER')</pre> </p>
<p><strong>Solution:</strong></p>
<pre class="crayon-plain-tag">;WITH CTE AS
(
	SELECT COUNT(1) AS IDCount, ID FROM tbl_TestTable GROUP BY ID
)
DELETE TOP((SELECT IDCount FROM CTE WHERE ID = 1) - 1) FROM tbl_TestTable  WHERE ID = 1</pre> </p>
<p><strong><code>Please try the different solution for this puzzle and share it via comment...</code></strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/06/sql-puzzle-delete-duplicate-data-without-primary-key-row_number/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
