Re: SQL question - problem with INTERSECT

From: "Keith L(dot) Musser" <kmusser(at)idisys(dot)com>
To: <igorr(at)crosswinds(dot)net>
Cc: "Dave Trepanier" <be164(at)yahoo(dot)com>, "PGSQL-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL question - problem with INTERSECT
Date: 2000-10-30 10:36:48
Message-ID: 000e01c0425d$55dccf60$0201a8c0@quantum.idisys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If I remove the "GROUP BY messages.msgid ...", then the result will be
messages whose subject contains either 'Hello' or 'There' in the
subject, but not necessarily both.

I want messages which have both 'Hello' and 'There' in the subject, and
both 'Jim' and 'Jones' in the author.

(For example, if I needed all of 'Hello', 'There', and 'Now' in the
subject, my first HAVING clause would use a count of 3, while the second
HAVING clause would still use a count of 2, for both 'Jim' and 'Jones'.)
So I cannot remove either having clause without changing the meaning.

What I would really like to know is why INTERSECT does not allow this.
If I understand that, maybe I can figure out how to get what I need.

-----Original Message-----
From: Igor Roboul <igor(at)raduga(dot)dyndns(dot)org>
To: PGSQL-General <pgsql-general(at)postgresql(dot)org>
Date: Wednesday, November 01, 2000 12:03 AM
Subject: Re: [GENERAL] SQL question - problem with INTERSECT

>On Mon, Oct 30, 2000 at 07:59:06PM -0500, Keith L. Musser wrote:
>> "(SELECT messages.msgid FROM messages, subject_index WHERE
>> ((subject_index.word='Hello' or subject_index.word='There') and
>> (subject_index.msgid = messages.msgid))
>> GROUP BY messages.msgid HAVING count(messages.msgid)=2)
>> INTERSECT
>> (SELECT messages.msgid FROM messages, author_index WHERE
>> ((author_index.word='Jim' or author_index.word='Jones') and
>> (author_index.msgid = messages.msgid))
>> GROUP BY messages.msgid HAVING count(messages.msgid)=2);"
>Try removing first "GROUP BY messages.msgid HAVING
count(messages.msgid)=2)"
>
>--
>Igor Roboul, Unix System Administrator & Programmer @ sanatorium
"Raduga",
>Sochi, Russia
>http://www.brainbench.com/transcript.jsp?pid=304744
>

Browse pgsql-general by date

  From Date Subject
Next Message Gangi Chen 2000-10-30 11:14:44 begin work failed
Previous Message K Parker 2000-10-30 06:32:21 Re: A question about PL/pgSQL