Re: Substract queries

Поиск
Список
Период
Сортировка
От Niklas Johansson
Тема Re: Substract queries
Дата
Msg-id 4A2B1477-9C08-4EF9-81F1-FED9A85D1E8F@tele2.se
обсуждение исходный текст
Ответ на Substract queries  ("Nacef LABIDI" <nacef.l@gmail.com>)
Список pgsql-sql
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





В списке pgsql-sql по дате отправления:

Предыдущее
От: "Nacef LABIDI"
Дата:
Сообщение: Re: Substract queries
Следующее
От: "Sebastian Rychter"
Дата:
Сообщение: Extremely Low performance with ODBC