SQL question - problem with INTERSECT - Mailing list pgsql-general

From Keith L. Musser
Subject SQL question - problem with INTERSECT
Date
Msg-id 001d01c042d5$c8ca1cd0$0201a8c0@quantum.idisys.com
Whole thread Raw
Responses Re: SQL question - problem with INTERSECT  (Igor Roboul <igor@raduga.dyndns.org>)
Re: SQL question - problem with INTERSECT  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi,

I want to do a complicated SQL query as follows:

"(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);"

The first SELECT is supposed to find messages whose subject contains
both 'Hello' and 'There'.  The second SELECT is supposed to find all
messages in which the author contains both 'Jim' and 'Jones'.  Each work
fine independently, but given me an error when combined with INTERSECT.

PGSQL doesn't accept the combination.  It gives me this error message:
"SELECT / HAVING requires aggregates to be valid".

Can somebody explain what this means, and how I should fix it?

Keith L. Musser
Integrated Dynamics, Inc.
812-371-7777
email:  kmusser@idisys.com





pgsql-general by date:

Previous
From: Alex Pilosov
Date:
Subject: Re: True ACID under linux (no fsync)?
Next
From: Gunnar R|nning
Date:
Subject: Re: how good is PostgreSQL