On Fri, 11 Apr 2003, Itai Zukerman wrote:
> > CREATE TABLE A (x int PRIMARY KEY, real v);
> > CREATE TABLE B (x int);
> >
> > I'd like to calculate:
> >
> > SELECT sum(v) FROM A WHERE EXISTS (SELECT 1 FROM B WHERE A.x=B.x);
>
> This seems to be a reasonably-performing workaround:
>
> SELECT DISTINCT x INTO TEMP C FROM A,B WHERE A.x=B.x;
> SELECT sum(v) FROM A,C WHERE A.x=C.x;
Hmm, given that, would something like:
select sum(v) from
(select distinct on(x) x,v from a,b where a.x=b.x) as foo;
work?