Re: Substract queries

From: "Nacef LABIDI" <nacef(dot)l(at)gmail(dot)com>
To: "Niklas Johansson" <spot(at)tele2(dot)se>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Substract queries
Date: 2008-05-22 15:49:24
Message-ID: f16f7ea00805220849s394e4de9yc031ae19d5166e0d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks to all the EXEPT keyword is what I was looking for

On Thu, May 22, 2008 at 5:36 PM, Niklas Johansson <spot(at)tele2(dot)se> wrote:

>
> On 22 maj 2008, at 17.15, Nacef LABIDI wrote:
>
>> I was wondering how can I substract result between select queries. I mean
>> I want to issue a query that does this :
>> (select * from mytable where condition1) - (select * from mytable where
>> condition2)
>>
>
> If you (as implied above) query the same table in both cases, just do:
>
> SELECT * FROM mytable WHERE condition1 AND NOT condition2
>
> Otherwise, use EXCEPT:
>
> SELECT * FROM mytable1 WHERE condition1
> EXCEPT
> SELECT * FROM mytable2 WHERE condition2
>
> in which case both queries must return the same type of rows.
>
>
>
>
> Sincerely,
>
> Niklas Johansson
>
>
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Sebastian Rychter 2008-05-22 18:29:23 Extremely Low performance with ODBC
Previous Message Niklas Johansson 2008-05-22 15:36:15 Re: Substract queries