intersect within a subquery

From: Phil Glatz <phil(at)glatz(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: intersect within a subquery
Date: 2001-11-21 21:31:57
Message-ID: 5.1.0.14.2.20011121131859.031a86a8@flawless.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a table cdb, indexed by cdb_id.
A second table map_flags to map to some other data. It has a cdb_id field,
used to link to cdb.

I want to select a subset of cdb where records with a specific cdb_id is
present in two rows in map_flags, so I created a subquery to pull the
records from map_flags, using INTERSECT. This query runs by itself ok, but
when I use it as a subquery, I get parse error at or near "intersect".

Isn't this legal?

SELECT c.cdb_id,c.company
FROM cdb c
WHERE c.cdb_id IN
(SELECT m.cdb_id FROM map_flags m
WHERE m.cflag_id=240
INTERSECT
SELECT m.cdb_id FROM map_flags m
WHERE m.cflag_id=30)
ORDER BY c.company;

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-11-21 22:02:30 Re: intersect within a subquery
Previous Message Peter Blajev 2001-11-21 21:12:20 Re: Ultradev and PostgreSQL on SuSE