Re: Performing intersection without intersect operator

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Nacef LABIDI <nacef(dot)l(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Performing intersection without intersect operator
Date: 2008-10-28 11:59:36
Message-ID: 4906FEA8.4020901@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Nacef LABIDI wrote:
> I want to perform an intersection between several select queries but
> without using the INTERSECT keyword.
>
> select userid from orders where productid=1 INTERSECT select userid from
> orders where productid=2
>
> I want to transform it without the INTERSECT.

(select userid from orders where productid=1 UNION select userid from
orders where productid=2) EXCEPT (select userid from orders where
productid=1 EXCEPT select userid from orders where productid=2) EXCEPT
(select userid from orders where productid=2 UNION select userid from
orders where productid=1)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2008-10-28 12:31:04 Re: How to hand over array as variable in plpgsql function?
Previous Message Oliveiros Cristina 2008-10-28 11:51:05 Re: Performing intersection without intersect operator