<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Relational division</title><link>http://sqlblog.com/blogs/peter_larsson/archive/2010/06/30/relational-algebra.aspx</link><description>I came across an interesting post on Microsoft SQL Server forum this afternoon. It was a question about Relational algebra and the poster wanted to have an efficient query to solve his problem. The original title was " Select parent ids that have exact</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Relational division</title><link>http://sqlblog.com/blogs/peter_larsson/archive/2010/06/30/relational-algebra.aspx#26626</link><pubDate>Wed, 30 Jun 2010 20:11:52 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26626</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;I think you forgot to mention what the problem is?&lt;/p&gt;
</description></item><item><title>re: Relational division</title><link>http://sqlblog.com/blogs/peter_larsson/archive/2010/06/30/relational-algebra.aspx#26631</link><pubDate>Wed, 30 Jun 2010 20:51:34 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26631</guid><dc:creator>Peso</dc:creator><description>&lt;p&gt;Oh, I thought the title said it all. &lt;/p&gt;
&lt;p&gt;The problem is to find an efficient query to deal with relational algebra.&lt;/p&gt;
&lt;p&gt;Mr Celko has a wonderful description of Relational Division and some examples here &lt;a rel="nofollow" target="_new" href="http://www.simple-talk.com/sql/t-sql-programming/divided-we-stand-the-sql-of-relational-division/"&gt;http://www.simple-talk.com/sql/t-sql-programming/divided-we-stand-the-sql-of-relational-division/&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The problem is that they are not very efficient queries. It's all about to find group of connected records which is evenly divided by a number of wanted records.&lt;/p&gt;
&lt;p&gt;For the example above, to find the ParentID(s) which have exactly ONE, TWO and THREE as keywords. Not less and certainly not more.&lt;/p&gt;
</description></item><item><title>re: Relational division</title><link>http://sqlblog.com/blogs/peter_larsson/archive/2010/06/30/relational-algebra.aspx#26695</link><pubDate>Fri, 02 Jul 2010 14:22:05 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26695</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;A more interesting challenge--and much closer to what Celko has done--is to make this work with TWO tables. The one you already have, plus:&lt;/p&gt;
&lt;p&gt;DECLARE @Sample2 TABLE&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;KeyID INT NOT NULL,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Keyword VARCHAR(25) NOT NULL,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;UNIQUE (KeyID, Keyword)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;)&lt;/p&gt;
&lt;p&gt;INSERT @Sample2&lt;/p&gt;
&lt;p&gt;VALUES &amp;nbsp;(6, 'one'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(6, 'two'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(6, 'three'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(6, 'four'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(7, 'one'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(7, 'two'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(7, 'three'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(8, 'one'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(8, 'two')&lt;/p&gt;
&lt;p&gt;Then the output of the division query would be:&lt;/p&gt;
&lt;p&gt;ParentID -- KeyID&lt;/p&gt;
&lt;p&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/p&gt;
&lt;p&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/p&gt;
&lt;p&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&lt;/p&gt;
</description></item><item><title>re: Relational division</title><link>http://sqlblog.com/blogs/peter_larsson/archive/2010/06/30/relational-algebra.aspx#26696</link><pubDate>Fri, 02 Jul 2010 14:28:06 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26696</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Actually there should probably be some invalid stuff in there too:&lt;/p&gt;
&lt;p&gt;INSERT @Sample2&lt;/p&gt;
&lt;p&gt;VALUES &amp;nbsp;(6, 'one'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (6, 'two'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (6, 'three'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (6, 'four'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (7, 'one'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (7, 'two'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (7, 'three'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (8, 'one'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (8, 'two'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (9, 'one'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (9, 'two'),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; (9, 'four')&lt;/p&gt;
</description></item><item><title>re: Relational division</title><link>http://sqlblog.com/blogs/peter_larsson/archive/2010/06/30/relational-algebra.aspx#26698</link><pubDate>Fri, 02 Jul 2010 15:17:45 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26698</guid><dc:creator>Peso</dc:creator><description>&lt;p&gt;Already ahead of you. Posted here&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://weblogs.sqlteam.com/peterl/archive/2010/07/02/Proper-Relational-Division-With-Sets.aspx"&gt;http://weblogs.sqlteam.com/peterl/archive/2010/07/02/Proper-Relational-Division-With-Sets.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Relational division</title><link>http://sqlblog.com/blogs/peter_larsson/archive/2010/06/30/relational-algebra.aspx#26700</link><pubDate>Fri, 02 Jul 2010 15:42:14 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26700</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Why do you only cross post certain things and then not the followup? Seems counter productive--and it's impossible for readers to keep track.&lt;/p&gt;
</description></item><item><title>re: Relational division</title><link>http://sqlblog.com/blogs/peter_larsson/archive/2010/06/30/relational-algebra.aspx#27725</link><pubDate>Mon, 09 Aug 2010 16:18:38 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:27725</guid><dc:creator>Naomi</dc:creator><description>&lt;p&gt;Agree with the last comment - post the whole solution with as many needed cross references in one blog.&lt;/p&gt;
</description></item></channel></rss>