<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Oracle Today - Latest Comments in Relational algebra: division in sql</title><link>http://oracletoday.disqus.com/</link><description></description><atom:link href="https://oracletoday.disqus.com/relational_algebra_division_in_sql/latest.rss" rel="self"></atom:link><language>en</language><lastBuildDate>Fri, 11 Sep 2009 05:22:33 -0000</lastBuildDate><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-16411440</link><description>&lt;p&gt;The post  is so interesting and easy to understand. Relational algebra and its step by step solution has made the sql unproblematic and simple. Thank you for sharing.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">rent limousine</dc:creator><pubDate>Fri, 11 Sep 2009 05:22:33 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-7353698</link><description>&lt;p&gt;There’s also this alternative approach which is usually more efficient:&lt;/p&gt;&lt;p&gt;SELECT name&lt;br&gt;FROM Student&lt;br&gt;WHERE SID IN ( SELECT SID&lt;br&gt;FROM Register&lt;br&gt;GROUP BY SID&lt;br&gt;HAVING COUNT(*) = (SELECT COUNT(*) FROM Course)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">hypnosis.course</dc:creator><pubDate>Thu, 19 Mar 2009 14:43:49 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-3881995</link><description>&lt;p&gt;There’s also this alternative approach which is usually more efficient:&lt;/p&gt;&lt;p&gt;SELECT name&lt;br&gt;FROM Student&lt;br&gt;WHERE SID IN ( SELECT SID&lt;br&gt;FROM Register&lt;br&gt;GROUP BY SID&lt;br&gt;HAVING COUNT(*) = (SELECT COUNT(*) FROM Course)&lt;br&gt;)&lt;/p&gt;&lt;p&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">buy wow gold</dc:creator><pubDate>Tue, 18 Nov 2008 14:33:30 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-825289</link><description>&lt;p&gt;The minus is a very costly affair, and your sql takes 10 times more time to execute than the otherquery you've posted and the one that I used  as below:&lt;/p&gt;&lt;p&gt;select sid from (select sid, count(sid) count &lt;br&gt;from (select distinct sid, pid from catalog) c, &lt;br&gt;parts p where &lt;a href="http://c.pid" rel="nofollow noopener" target="_blank" title="c.pid"&gt;c.pid&lt;/a&gt; = &lt;a href="http://p.pid" rel="nofollow noopener" target="_blank" title="p.pid"&gt;p.pid&lt;/a&gt; group by sid) s &lt;br&gt;where s.count = (select count(distinct pid) from parts)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aparna</dc:creator><pubDate>Mon, 07 Jul 2008 01:59:52 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-346028</link><description>&lt;p&gt;Yas,&lt;/p&gt;&lt;p&gt;Thanks for your postings and comments regarding Relational Algebra: division in sql!&lt;/p&gt;&lt;p&gt;elai&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">elai</dc:creator><pubDate>Thu, 17 Apr 2008 02:25:36 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-346020</link><description>&lt;p&gt;elai, yours also works.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">yas</dc:creator><pubDate>Thu, 17 Apr 2008 02:21:04 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-345999</link><description>&lt;p&gt;How about these two sets of queries for division in the case of having all red parts:&lt;/p&gt;&lt;p&gt;select distinct sid&lt;br&gt;from catalog c, parts p&lt;br&gt;where &lt;a href="http://c.pid" rel="nofollow noopener" target="_blank" title="c.pid"&gt;c.pid&lt;/a&gt; = &lt;a href="http://p.pid" rel="nofollow noopener" target="_blank" title="p.pid"&gt;p.pid&lt;/a&gt; and color = 'Red'&lt;br&gt;group by sid&lt;br&gt;having count(distinct &lt;a href="http://c.pid" rel="nofollow noopener" target="_blank" title="c.pid"&gt;c.pid&lt;/a&gt;) =&lt;br&gt;(select count(distinct pid)&lt;br&gt;from parts&lt;br&gt;where color = 'Red');&lt;/p&gt;&lt;p&gt;select distinct sid&lt;br&gt;from catalog c1&lt;br&gt;where not exists (&lt;br&gt;(select pid&lt;br&gt;from parts&lt;br&gt;where color = 'Red')&lt;br&gt;minus&lt;br&gt;(slect pid&lt;br&gt;from catalog c2&lt;br&gt;where c1.sid = c2.sid));&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">elai</dc:creator><pubDate>Thu, 17 Apr 2008 02:09:48 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-341345</link><description>&lt;p&gt;How about these two sets of queries for division:&lt;/p&gt;&lt;p&gt;select  distinct sid&lt;br&gt;from    catalog c, parts p&lt;br&gt;where &lt;a href="http://c.pid" rel="nofollow noopener" target="_blank" title="c.pid"&gt;c.pid&lt;/a&gt; = &lt;a href="http://p.pid" rel="nofollow noopener" target="_blank" title="p.pid"&gt;p.pid&lt;/a&gt;&lt;br&gt;group by sid&lt;br&gt;having count(distinct &lt;a href="http://c.pid" rel="nofollow noopener" target="_blank" title="c.pid"&gt;c.pid&lt;/a&gt;) =&lt;br&gt;(select count(distinct pid)&lt;br&gt; from    parts);&lt;/p&gt;&lt;p&gt;select distinct sid&lt;br&gt;from    catalog c1&lt;br&gt;where not exists (&lt;br&gt;(select pid&lt;br&gt;  from parts)&lt;br&gt;minus&lt;br&gt;(slect pid&lt;br&gt; from  catalog c2&lt;br&gt; where c1.sid = c2.sid));&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">elai</dc:creator><pubDate>Wed, 16 Apr 2008 07:06:45 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-319784</link><description>&lt;p&gt;Sorry, you are using a different sql in your last post. That does not work in 10.2 either.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">yas</dc:creator><pubDate>Thu, 10 Apr 2008 08:08:38 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-319705</link><description>&lt;p&gt;Laurent, it works in 10.2.0.2. I did not try it on 10G R1.&lt;/p&gt;&lt;p&gt;SQL&amp;gt; r&lt;br&gt;  1  select sid from&lt;br&gt;  2  (select sid,cast(collect(parts_t(pid)) as parts_tt) x from catalog group by sid)&lt;br&gt;  3  where&lt;br&gt;  4* ((select cast(collect(parts_t(pid))as parts_tt) from parts)) submultiset x&lt;/p&gt;&lt;p&gt;       SID&lt;br&gt;----------&lt;br&gt;         1&lt;/p&gt;&lt;p&gt;SQL&amp;gt; select * from v$version;&lt;/p&gt;&lt;p&gt;BANNER&lt;br&gt;----------------------------------------------------------------&lt;br&gt;Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi&lt;br&gt;PL/SQL Release 10.2.0.2.0 - Production&lt;br&gt;CORE    10.2.0.2.0      Production&lt;br&gt;TNS for Solaris: Version 10.2.0.2.0 - Production&lt;br&gt;NLSRTL Version 10.2.0.2.0 - Production&lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">yas</dc:creator><pubDate>Thu, 10 Apr 2008 07:32:36 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-319696</link><description>&lt;p&gt;unfortunately it is quite underused, and it is not working as I expect it to do :&lt;br&gt;&lt;code&gt;&lt;br&gt;SQL&amp;gt; select sid&lt;br&gt;  2  from catalog&lt;br&gt;  3  group by sid&lt;br&gt;  4  having&lt;br&gt;  5    (select cast(collect(parts_t(pid))as parts_tt) from parts)&lt;br&gt;  6      submultiset&lt;br&gt;  7*   cast(collect(parts_t(pid)) as parts_tt)&lt;br&gt;select sid&lt;br&gt;*&lt;br&gt;ERROR at line 1:&lt;br&gt;ORA-00979: not a GROUP BY expression&lt;br&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;the ORA-979 makes no sense. I will open a SR and it may be fixed in Oracle 15&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Laurent Schneider</dc:creator><pubDate>Thu, 10 Apr 2008 07:27:24 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-319670</link><description>&lt;p&gt;Laurent, thanks for the great solution. I did not even know something like submultiset was available.&lt;/p&gt;&lt;p&gt;For the ones interested: submultiset does not exist in 9.2, it comes with 10G R1. It is used to find out if a nested table is a subset of another nested table. Documentation about it is &lt;a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions006.htm#i1050570" rel="nofollow noopener" target="_blank" title="http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions006.htm#i1050570"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Thanks again Laurent.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">yas</dc:creator><pubDate>Thu, 10 Apr 2008 07:09:54 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-319653</link><description>&lt;p&gt;well, this does not cover when supplier have more pieces than parts. So maybe this :&lt;/p&gt;&lt;p&gt;&lt;code&gt;create or replace type parts_t as object (pid number);&lt;br&gt;/&lt;br&gt;create or replace type parts_tt as table of parts_t;&lt;br&gt;/&lt;br&gt;select sid from &lt;br&gt;  (select sid,cast(collect(parts_t(pid)) as parts_tt) x from catalog group by sid)&lt;br&gt;where  &lt;br&gt;  ((select cast(collect(parts_t(pid))as parts_tt) from parts)) submultiset x;&lt;br&gt;&lt;/code&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Laurent Schneider</dc:creator><pubDate>Thu, 10 Apr 2008 06:48:51 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-319631</link><description>&lt;p&gt;what about this :&lt;br&gt;&lt;code&gt;&lt;br&gt;select sid from catalog &lt;br&gt;group by sid&lt;br&gt;having collect(pid) = (select collect(pid) from parts);&lt;br&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;well, it is maybe slower&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Laurent Schneider</dc:creator><pubDate>Thu, 10 Apr 2008 06:25:05 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-319384</link><description>&lt;p&gt;In this case it works. In some other cases it might not. Suppose products have some properties like color. What if I want the suppliers supplying all the red parts?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">yas</dc:creator><pubDate>Thu, 10 Apr 2008 02:09:23 -0000</pubDate></item><item><title>Re: Relational algebra: division in sql</title><link>http://oracletoday.blogspot.com/2008/04/relational-algebra-division-in-sql.html#comment-319228</link><description>&lt;p&gt;I think this different approach should also work:&lt;br&gt;select sid, count(*) total &lt;br&gt;  from catalog&lt;br&gt; group by sid having count(*) = &lt;br&gt;       (select count(*) from parts); &lt;br&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ric</dc:creator><pubDate>Thu, 10 Apr 2008 00:26:58 -0000</pubDate></item></channel></rss>