intersect within a subquery

Started by Phil Glatzover 24 years ago2 messagesgeneral
Jump to latest
#1Phil Glatz
phil@glatz.com

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;

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Phil Glatz (#1)
Re: intersect within a subquery

Phil Glatz <phil@glatz.com> writes:

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".

You need a newer PG release, evidently.

regards, tom lane