Re: Substract queries
От | Nacef LABIDI |
---|---|
Тема | Re: Substract queries |
Дата | |
Msg-id | f16f7ea00805220849s394e4de9yc031ae19d5166e0d@mail.gmail.com обсуждение исходный текст |
Ответ на | Substract queries ("Nacef LABIDI" <nacef.l@gmail.com>) |
Список | pgsql-sql |
Thanks to all the EXEPT keyword is what I was looking for<br /><br /><div class="gmail_quote">On Thu, May 22, 2008 at 5:36PM, Niklas Johansson <<a href="mailto:spot@tele2.se">spot@tele2.se</a>> wrote:<br /><blockquote class="gmail_quote"style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><divclass="Ih2E3d"><br /> On 22 maj 2008, at 17.15, Nacef LABIDI wrote:<br /><blockquote class="gmail_quote" style="border-left:1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> I was wondering how canI substract result between select queries. I mean I want to issue a query that does this :<br /> (select * from mytablewhere condition1) - (select * from mytable where condition2)<br /></blockquote><br /></div> If you (as implied above)query the same table in both cases, just do:<br /><br /> SELECT * FROM mytable WHERE condition1 AND NOT condition2<br/><br /> Otherwise, use EXCEPT:<br /><br /> SELECT * FROM mytable1 WHERE condition1<br /> EXCEPT<br /> SELECT* FROM mytable2 WHERE condition2<br /><br /> in which case both queries must return the same type of rows.<br /><br/><br /><br /><br /> Sincerely,<br /><font color="#888888"><br /> Niklas Johansson<br /><br /><br /><br /></font></blockquote></div><br/>
В списке pgsql-sql по дате отправления: