<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Interesting Interview Questions &#8211; Part 2 &#8211; Puzzle &#8211; Solution</title>
	<atom:link href="http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 10 Feb 2012 02:12:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Sam</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-74576</link>
		<dc:creator><![CDATA[Sam]]></dc:creator>
		<pubDate>Thu, 03 Jun 2010 11:54:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-74576</guid>
		<description><![CDATA[SELECT Name
FROM PersonColors pc
INNER JOIN SelectedColors sc ON sc.ColorCode = pc.ColorCode
GROUP BY pc.Name
HAVING COUNT(distinct pc.ColorCode) &gt;= (SELECT COUNT(ColorCode) FROM SelectedColors)]]></description>
		<content:encoded><![CDATA[<p>SELECT Name<br />
FROM PersonColors pc<br />
INNER JOIN SelectedColors sc ON sc.ColorCode = pc.ColorCode<br />
GROUP BY pc.Name<br />
HAVING COUNT(distinct pc.ColorCode) &gt;= (SELECT COUNT(ColorCode) FROM SelectedColors)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-58805</link>
		<dc:creator><![CDATA[Brian Tkatch]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 14:37:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-58805</guid>
		<description><![CDATA[@Rahul

That behavior is in SQL Server 2008, not 2005.]]></description>
		<content:encoded><![CDATA[<p>@Rahul</p>
<p>That behavior is in SQL Server 2008, not 2005.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rahul Bhargava</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-58787</link>
		<dc:creator><![CDATA[Rahul Bhargava]]></dc:creator>
		<pubDate>Fri, 18 Dec 2009 07:02:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-58787</guid>
		<description><![CDATA[Hi Brian,
When i executes 
CREATE TABLE PersonColors (Name VARCHAR(100), ColorCode VARCHAR(100))
GO
Then table creation is successfull but when i inserts data in 

INSERT INTO PersonColors (Name,ColorCode)
VALUES (&#039;Tom&#039;,&#039;Red&#039;),(&#039;Tom&#039;,&#039;Blue&#039;),(&#039;Tom&#039;,&#039;Green&#039;),(&#039;Tom&#039;,&#039;Brown&#039;),
(&#039;Mike&#039;,&#039;Red&#039;),(&#039;Mike&#039;,&#039;Blue&#039;),
(&#039;James&#039;,&#039;Green&#039;),(&#039;James&#039;,&#039;Brown&#039;),
(&#039;Joe&#039;,&#039;Red&#039;),(&#039;Joe&#039;,&#039;Blue&#039;),(&#039;Joe&#039;,&#039;Green&#039;),
(&#039;Matt&#039;,&#039;Brown&#039;)
GO

This way it gives error

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near &#039;,&#039;.

Thanks 
Rahul]]></description>
		<content:encoded><![CDATA[<p>Hi Brian,<br />
When i executes<br />
CREATE TABLE PersonColors (Name VARCHAR(100), ColorCode VARCHAR(100))<br />
GO<br />
Then table creation is successfull but when i inserts data in </p>
<p>INSERT INTO PersonColors (Name,ColorCode)<br />
VALUES (&#8216;Tom&#8217;,'Red&#8217;),(&#8216;Tom&#8217;,'Blue&#8217;),(&#8216;Tom&#8217;,'Green&#8217;),(&#8216;Tom&#8217;,'Brown&#8217;),<br />
(&#8216;Mike&#8217;,'Red&#8217;),(&#8216;Mike&#8217;,'Blue&#8217;),<br />
(&#8216;James&#8217;,'Green&#8217;),(&#8216;James&#8217;,'Brown&#8217;),<br />
(&#8216;Joe&#8217;,'Red&#8217;),(&#8216;Joe&#8217;,'Blue&#8217;),(&#8216;Joe&#8217;,'Green&#8217;),<br />
(&#8216;Matt&#8217;,'Brown&#8217;)<br />
GO</p>
<p>This way it gives error</p>
<p>Msg 102, Level 15, State 1, Line 2<br />
Incorrect syntax near &#8216;,&#8217;.</p>
<p>Thanks<br />
Rahul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-58766</link>
		<dc:creator><![CDATA[Brian Tkatch]]></dc:creator>
		<pubDate>Thu, 17 Dec 2009 14:46:39 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-58766</guid>
		<description><![CDATA[@Rahul

What exactly is the problem. Can you show a statement that generates an error?]]></description>
		<content:encoded><![CDATA[<p>@Rahul</p>
<p>What exactly is the problem. Can you show a statement that generates an error?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rahul Bhargava</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-58755</link>
		<dc:creator><![CDATA[Rahul Bhargava]]></dc:creator>
		<pubDate>Thu, 17 Dec 2009 12:25:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-58755</guid>
		<description><![CDATA[Hi,
I am using SQL Server 2005 and many times i have tried with single insert statements having multiple values always gives error .
what can be the reason?

To insert i used your way 

CREATE TABLE PersonColors (Name VARCHAR(100), ColorCode VARCHAR(100))
GO
INSERT INTO PersonColors ([Name],ColorCode)
SELECT &#039;Tom&#039;,&#039;Blue&#039;
UNION ALL
SELECT &#039;Tom&#039;,&#039;Green&#039;
UNION ALL 
SELECT &#039;Tom&#039;,&#039;Brown&#039;
UNION ALL 
SELECT&#039;Mike&#039;,&#039;Red&#039;
UNION ALL 
SELECT &#039;Mike&#039;,&#039;Blue&#039;
UNION ALL 
SELECT&#039;James&#039;,&#039;Green&#039;
UNION ALL 
SELECT&#039;James&#039;,&#039;Brown&#039;
UNION ALL
SELECT &#039;Joe&#039;,&#039;Red&#039;
UNION ALL 
SELECT &#039;Joe&#039;,&#039;Blue&#039;
UNION ALL 
SELECT&#039;Joe&#039;,&#039;Green&#039;
UNION ALL
SELECT &#039;Matt&#039;,&#039;Brown&#039;
GO
SELECT *
FROM PersonColors
GO		
/*Create Second Table SelectedColors*/
CREATE TABLE SelectedColors (ColorCode VARCHAR(100))
GO
INSERT INTO SelectedColors (ColorCode)
SELECT &#039;Red&#039;
UNION ALL 
SELECT  &#039;Blue&#039;
UNION ALL .
SELECT &#039;Green&#039; 
SELECT *
FROM PersonColors
SELECT *
FROM SelectedColors
GO]]></description>
		<content:encoded><![CDATA[<p>Hi,<br />
I am using SQL Server 2005 and many times i have tried with single insert statements having multiple values always gives error .<br />
what can be the reason?</p>
<p>To insert i used your way </p>
<p>CREATE TABLE PersonColors (Name VARCHAR(100), ColorCode VARCHAR(100))<br />
GO<br />
INSERT INTO PersonColors ([Name],ColorCode)<br />
SELECT &#8216;Tom&#8217;,'Blue&#8217;<br />
UNION ALL<br />
SELECT &#8216;Tom&#8217;,'Green&#8217;<br />
UNION ALL<br />
SELECT &#8216;Tom&#8217;,'Brown&#8217;<br />
UNION ALL<br />
SELECT&#8217;Mike&#8217;,'Red&#8217;<br />
UNION ALL<br />
SELECT &#8216;Mike&#8217;,'Blue&#8217;<br />
UNION ALL<br />
SELECT&#8217;James&#8217;,'Green&#8217;<br />
UNION ALL<br />
SELECT&#8217;James&#8217;,'Brown&#8217;<br />
UNION ALL<br />
SELECT &#8216;Joe&#8217;,'Red&#8217;<br />
UNION ALL<br />
SELECT &#8216;Joe&#8217;,'Blue&#8217;<br />
UNION ALL<br />
SELECT&#8217;Joe&#8217;,'Green&#8217;<br />
UNION ALL<br />
SELECT &#8216;Matt&#8217;,'Brown&#8217;<br />
GO<br />
SELECT *<br />
FROM PersonColors<br />
GO<br />
/*Create Second Table SelectedColors*/<br />
CREATE TABLE SelectedColors (ColorCode VARCHAR(100))<br />
GO<br />
INSERT INTO SelectedColors (ColorCode)<br />
SELECT &#8216;Red&#8217;<br />
UNION ALL<br />
SELECT  &#8216;Blue&#8217;<br />
UNION ALL .<br />
SELECT &#8216;Green&#8217;<br />
SELECT *<br />
FROM PersonColors<br />
SELECT *<br />
FROM SelectedColors<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tejas Shah</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-54667</link>
		<dc:creator><![CDATA[Tejas Shah]]></dc:creator>
		<pubDate>Mon, 10 Aug 2009 05:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-54667</guid>
		<description><![CDATA[@Surya,

You are correct, we will get TOM in that case.

But please read post, there is already note like:

UPDATE: Following solution is written with assumption that in SelectedColors table Name and ColorCode are Primary Key. This requirement was not specified in original question.

Thanks,

Tejas]]></description>
		<content:encoded><![CDATA[<p>@Surya,</p>
<p>You are correct, we will get TOM in that case.</p>
<p>But please read post, there is already note like:</p>
<p>UPDATE: Following solution is written with assumption that in SelectedColors table Name and ColorCode are Primary Key. This requirement was not specified in original question.</p>
<p>Thanks,</p>
<p>Tejas</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Surya</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-54616</link>
		<dc:creator><![CDATA[Surya]]></dc:creator>
		<pubDate>Sat, 08 Aug 2009 11:41:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-54616</guid>
		<description><![CDATA[If you insert data as mentioned below
(&#039;Tom&#039;,&#039;Red&#039;),(&#039;Tom&#039;,&#039;Blue&#039;), (&#039;Tom&#039;,&#039;Red&#039;),(&#039;Tom&#039;,&#039;Blue&#039;) 
you will get Tom in output which is wrong...]]></description>
		<content:encoded><![CDATA[<p>If you insert data as mentioned below<br />
(&#8216;Tom&#8217;,'Red&#8217;),(&#8216;Tom&#8217;,'Blue&#8217;), (&#8216;Tom&#8217;,'Red&#8217;),(&#8216;Tom&#8217;,'Blue&#8217;)<br />
you will get Tom in output which is wrong&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gangadhar Naidu</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-53744</link>
		<dc:creator><![CDATA[Gangadhar Naidu]]></dc:creator>
		<pubDate>Thu, 16 Jul 2009 04:27:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-53744</guid>
		<description><![CDATA[If you use distinct in the having count then you can avoid duplicates in both tables.

SELECT Name

FROM PersonColors pc

INNER JOIN SelectedColors sc ON sc.ColorCode = pc.ColorCode

GROUP BY pc.Name

HAVING COUNT(distinct pc.ColorCode) &gt;= (SELECT COUNT(distinct ColorCode) FROM SelectedColors)]]></description>
		<content:encoded><![CDATA[<p>If you use distinct in the having count then you can avoid duplicates in both tables.</p>
<p>SELECT Name</p>
<p>FROM PersonColors pc</p>
<p>INNER JOIN SelectedColors sc ON sc.ColorCode = pc.ColorCode</p>
<p>GROUP BY pc.Name</p>
<p>HAVING COUNT(distinct pc.ColorCode) &gt;= (SELECT COUNT(distinct ColorCode) FROM SelectedColors)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-53546</link>
		<dc:creator><![CDATA[Brian Tkatch]]></dc:creator>
		<pubDate>Wed, 08 Jul 2009 13:59:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-53546</guid>
		<description><![CDATA[@Leandro

There&#039;s always room for improvement. :)

Thanx for your contribution.]]></description>
		<content:encoded><![CDATA[<p>@Leandro</p>
<p>There&#8217;s always room for improvement. :)</p>
<p>Thanx for your contribution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leandro</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-53540</link>
		<dc:creator><![CDATA[Leandro]]></dc:creator>
		<pubDate>Wed, 08 Jul 2009 09:24:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-53540</guid>
		<description><![CDATA[@Brian Tkatch

Sorry, I missed that. But assuming that there ia no need to have the greater or equal comparison here: COUNT(pc.ColorCode) &gt;= (SELECT COUNT(ColorCode) FROM SelectedColors). Assuming that &quot;hidden&quot; key (:-p) we can use just the equal comparison like this: COUNT(pc.ColorCode) = (SELECT COUNT(ColorCode) FROM SelectedColors).



Just a tinny little tune up...

Cheers,
Leandro Nunes]]></description>
		<content:encoded><![CDATA[<p>@Brian Tkatch</p>
<p>Sorry, I missed that. But assuming that there ia no need to have the greater or equal comparison here: COUNT(pc.ColorCode) &gt;= (SELECT COUNT(ColorCode) FROM SelectedColors). Assuming that &#8220;hidden&#8221; key (:-p) we can use just the equal comparison like this: COUNT(pc.ColorCode) = (SELECT COUNT(ColorCode) FROM SelectedColors).</p>
<p>Just a tinny little tune up&#8230;</p>
<p>Cheers,<br />
Leandro Nunes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-53522</link>
		<dc:creator><![CDATA[Brian Tkatch]]></dc:creator>
		<pubDate>Tue, 07 Jul 2009 17:30:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-53522</guid>
		<description><![CDATA[@Leandro

&quot;Following solution is written with assumption that in SelectedColors table Name and ColorCode are Primary Key. This requirement was not specified in original question.&quot;]]></description>
		<content:encoded><![CDATA[<p>@Leandro</p>
<p>&#8220;Following solution is written with assumption that in SelectedColors table Name and ColorCode are Primary Key. This requirement was not specified in original question.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leandro</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-53519</link>
		<dc:creator><![CDATA[Leandro]]></dc:creator>
		<pubDate>Tue, 07 Jul 2009 16:29:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-53519</guid>
		<description><![CDATA[HI. 

pinaldave sorry to say but your answer is not correct...

Take a look:

If you run this:

delete from personcolors where name=&#039;Tom&#039; and ColorCode=&#039;Red&#039;;
insert into personcolors values(&#039;Tom&#039;, &#039;Blue&#039;);

The person Tom has three colors: green, brown and blue. Right now this user should not appear on the result set because he&#039;s missing red color. Guess what? Running your query he is still shown on the result set (because he has two blue lines) :(

For this query to work it should be written like this:

SELECT Name
FROM PersonColors pc
INNER JOIN SelectedColors sc ON sc.ColorCode = pc.ColorCode
GROUP BY pc.Name
HAVING COUNT(distinct pc.ColorCode) = (SELECT COUNT(ColorCode) FROM SelectedColors)

The only difference is that i&#039;m using COUNT(distinct pc.ColorCode). 

My first solution was pretty much like yours, but after awhile I relized that it was not correct :-D

I&#039;m a great fan of your blog
Greetings from Portugal ;-)

Leandro Nunes]]></description>
		<content:encoded><![CDATA[<p>HI. </p>
<p>pinaldave sorry to say but your answer is not correct&#8230;</p>
<p>Take a look:</p>
<p>If you run this:</p>
<p>delete from personcolors where name=&#8217;Tom&#8217; and ColorCode=&#8217;Red&#8217;;<br />
insert into personcolors values(&#8216;Tom&#8217;, &#8216;Blue&#8217;);</p>
<p>The person Tom has three colors: green, brown and blue. Right now this user should not appear on the result set because he&#8217;s missing red color. Guess what? Running your query he is still shown on the result set (because he has two blue lines) :(</p>
<p>For this query to work it should be written like this:</p>
<p>SELECT Name<br />
FROM PersonColors pc<br />
INNER JOIN SelectedColors sc ON sc.ColorCode = pc.ColorCode<br />
GROUP BY pc.Name<br />
HAVING COUNT(distinct pc.ColorCode) = (SELECT COUNT(ColorCode) FROM SelectedColors)</p>
<p>The only difference is that i&#8217;m using COUNT(distinct pc.ColorCode). </p>
<p>My first solution was pretty much like yours, but after awhile I relized that it was not correct :-D</p>
<p>I&#8217;m a great fan of your blog<br />
Greetings from Portugal ;-)</p>
<p>Leandro Nunes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Krimish Shah</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-51817</link>
		<dc:creator><![CDATA[Krimish Shah]]></dc:creator>
		<pubDate>Tue, 12 May 2009 14:10:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-51817</guid>
		<description><![CDATA[select P.Name from personcolors P inner join selectedcolors S on P.colorcode=s.colorcode
group by P.Name
having COUNT(*)= (select COUNT(*) from selectedcolors)]]></description>
		<content:encoded><![CDATA[<p>select P.Name from personcolors P inner join selectedcolors S on P.colorcode=s.colorcode<br />
group by P.Name<br />
having COUNT(*)= (select COUNT(*) from selectedcolors)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - Interesting Interview Questions - Part 2 - Puzzle Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-47563</link>
		<dc:creator><![CDATA[SQL SERVER - Interesting Interview Questions - Part 2 - Puzzle Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Fri, 27 Feb 2009 07:01:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-47563</guid>
		<description><![CDATA[[...] Click here for Solution. (Go live on 12/11/2008)  [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Click here for Solution. (Go live on 12/11/2008)  [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dj</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-46366</link>
		<dc:creator><![CDATA[dj]]></dc:creator>
		<pubDate>Thu, 05 Feb 2009 13:40:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-46366</guid>
		<description><![CDATA[DECLARE @cnt int
SELECT @cnt = COUNT(distinct colorcode) FROM selectedcolors
SELECT NAME FROM (
	SELECT NAME,COUNT(DISTINCT scl.ColorCode) ColorCode FROM PersonColors n 
	INNER JOIN SelectedColors scl ON n.ColorCode = scl.ColorCode
	GROUP BY NAME
	HAVING COUNT(DISTINCT scl.ColorCode) = @cnt

) Q]]></description>
		<content:encoded><![CDATA[<p>DECLARE @cnt int<br />
SELECT @cnt = COUNT(distinct colorcode) FROM selectedcolors<br />
SELECT NAME FROM (<br />
	SELECT NAME,COUNT(DISTINCT scl.ColorCode) ColorCode FROM PersonColors n<br />
	INNER JOIN SelectedColors scl ON n.ColorCode = scl.ColorCode<br />
	GROUP BY NAME<br />
	HAVING COUNT(DISTINCT scl.ColorCode) = @cnt</p>
<p>) Q</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-45925</link>
		<dc:creator><![CDATA[Simon]]></dc:creator>
		<pubDate>Fri, 23 Jan 2009 06:09:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-45925</guid>
		<description><![CDATA[If there is a primary key on Name and ColorCode I&#039;m having trouble understanding why the having clause uses greater than or equal. Shouldn&#039;t it be just equal?]]></description>
		<content:encoded><![CDATA[<p>If there is a primary key on Name and ColorCode I&#8217;m having trouble understanding why the having clause uses greater than or equal. Shouldn&#8217;t it be just equal?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Poonam</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-45028</link>
		<dc:creator><![CDATA[Poonam]]></dc:creator>
		<pubDate>Tue, 23 Dec 2008 11:33:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-45028</guid>
		<description><![CDATA[i try this  query

select   name from PersonColors
where colorcode in(select colorcode from SelectedColors)
group by name


is it correct please reply...]]></description>
		<content:encoded><![CDATA[<p>i try this  query</p>
<p>select   name from PersonColors<br />
where colorcode in(select colorcode from SelectedColors)<br />
group by name</p>
<p>is it correct please reply&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anil</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-44755</link>
		<dc:creator><![CDATA[Anil]]></dc:creator>
		<pubDate>Fri, 12 Dec 2008 14:54:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-44755</guid>
		<description><![CDATA[wow.. that&#039;s very good question.

i got same answer, please give me some more this type of question so that i can improve my knowledge.]]></description>
		<content:encoded><![CDATA[<p>wow.. that&#8217;s very good question.</p>
<p>i got same answer, please give me some more this type of question so that i can improve my knowledge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sirish</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-44748</link>
		<dc:creator><![CDATA[Sirish]]></dc:creator>
		<pubDate>Fri, 12 Dec 2008 12:42:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-44748</guid>
		<description><![CDATA[SELECT distinct Name
FROM #PersonColors PC
INNER JOIN #SelectedColors SC on 
SC.ColorCode=PC.ColorCode 
Group by Name
HAving Count(PC.ColorCode) &gt;=
(Select Count(1) from #SelectedColors)]]></description>
		<content:encoded><![CDATA[<p>SELECT distinct Name<br />
FROM #PersonColors PC<br />
INNER JOIN #SelectedColors SC on<br />
SC.ColorCode=PC.ColorCode<br />
Group by Name<br />
HAving Count(PC.ColorCode) &gt;=<br />
(Select Count(1) from #SelectedColors)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-44740</link>
		<dc:creator><![CDATA[Ben]]></dc:creator>
		<pubDate>Fri, 12 Dec 2008 00:14:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-44740</guid>
		<description><![CDATA[doh! I just read the update about the primary key.]]></description>
		<content:encoded><![CDATA[<p>doh! I just read the update about the primary key.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-44739</link>
		<dc:creator><![CDATA[Ben]]></dc:creator>
		<pubDate>Fri, 12 Dec 2008 00:01:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-44739</guid>
		<description><![CDATA[The posted answer will fail if there are multiple identical rows i.e. three rows that say Mark, Green.  Mark will appear even though he only has one of the colors...]]></description>
		<content:encoded><![CDATA[<p>The posted answer will fail if there are multiple identical rows i.e. three rows that say Mark, Green.  Mark will appear even though he only has one of the colors&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-44732</link>
		<dc:creator><![CDATA[Josh]]></dc:creator>
		<pubDate>Thu, 11 Dec 2008 16:44:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-44732</guid>
		<description><![CDATA[Wow, I&#039;m just excited that I got the same answer! :)

That is an interesting puzzle, I&#039;ve never had that sort of problem before &quot;in real life&quot; but it was fun.

I&#039;m a newer reader to your blog, but do you have additional T-SQL puzzles like that (or in general)?

Thank you!]]></description>
		<content:encoded><![CDATA[<p>Wow, I&#8217;m just excited that I got the same answer! :)</p>
<p>That is an interesting puzzle, I&#8217;ve never had that sort of problem before &#8220;in real life&#8221; but it was fun.</p>
<p>I&#8217;m a newer reader to your blog, but do you have additional T-SQL puzzles like that (or in general)?</p>
<p>Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chandra Sekhar</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-44720</link>
		<dc:creator><![CDATA[Chandra Sekhar]]></dc:creator>
		<pubDate>Thu, 11 Dec 2008 06:26:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-44720</guid>
		<description><![CDATA[Hi Dave,

I just looked into the site and recognized the style of insertion into the table like this

INSERT INTO PersonColors (Name,ColorCode)
VALUES (‘Tom’,‘Red’),(‘Tom’,‘Blue’),(‘Tom’,‘Green’),(‘Tom’,‘Brown’),
(‘Mike’,‘Red’),(‘Mike’,‘Blue’),
(‘James’,‘Green’),(‘James’,‘Brown’),
(‘Joe’,‘Red’),(‘Joe’,‘Blue’),(‘Joe’,‘Green’),
(‘Matt’,‘Brown’)

As all in my past I used to insert only one record at a time.  And I was amazed at looking this that we can insert multiple records with in a single insert statement.  But sadly, my it failed in my machine.  The more interesting is I accidentally inserted a duplicate record into the SelectedColors table with the value &#039;Red&#039; two times.  I tried to delete only the duplicate.  But cannot do that without deleting the &#039;Red&#039; items.  I tried in the GUI grid also to delete only one record.  That failed to do this.  Is there any work around for this rather than deleting all the records.]]></description>
		<content:encoded><![CDATA[<p>Hi Dave,</p>
<p>I just looked into the site and recognized the style of insertion into the table like this</p>
<p>INSERT INTO PersonColors (Name,ColorCode)<br />
VALUES (‘Tom’,‘Red’),(‘Tom’,‘Blue’),(‘Tom’,‘Green’),(‘Tom’,‘Brown’),<br />
(‘Mike’,‘Red’),(‘Mike’,‘Blue’),<br />
(‘James’,‘Green’),(‘James’,‘Brown’),<br />
(‘Joe’,‘Red’),(‘Joe’,‘Blue’),(‘Joe’,‘Green’),<br />
(‘Matt’,‘Brown’)</p>
<p>As all in my past I used to insert only one record at a time.  And I was amazed at looking this that we can insert multiple records with in a single insert statement.  But sadly, my it failed in my machine.  The more interesting is I accidentally inserted a duplicate record into the SelectedColors table with the value &#8216;Red&#8217; two times.  I tried to delete only the duplicate.  But cannot do that without deleting the &#8216;Red&#8217; items.  I tried in the GUI grid also to delete only one record.  That failed to do this.  Is there any work around for this rather than deleting all the records.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mumu</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-44717</link>
		<dc:creator><![CDATA[mumu]]></dc:creator>
		<pubDate>Thu, 11 Dec 2008 04:59:20 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-44717</guid>
		<description><![CDATA[What&#039;s makes this question a good one is that I used this answer in real-life in a report query a few months back.]]></description>
		<content:encoded><![CDATA[<p>What&#8217;s makes this question a good one is that I used this answer in real-life in a report query a few months back.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan</title>
		<link>http://blog.sqlauthority.com/2008/12/11/sql-server-interesting-interview-questions-part-2-puzzle-solution/#comment-44711</link>
		<dc:creator><![CDATA[Nathan]]></dc:creator>
		<pubDate>Thu, 11 Dec 2008 03:14:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=1652#comment-44711</guid>
		<description><![CDATA[Never mind I&#039;m wrong :)]]></description>
		<content:encoded><![CDATA[<p>Never mind I&#8217;m wrong :)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

