pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedQuery Help using Except
2+ messages / 2 participants
[nested] [flat]
* Query Help using Except
@ 2003-10-23 18:17 yusuf0478@netscape.net
2003-10-27 03:34 ` Re: Query Help using Except Bruno Wolff III <bruno@wolff.to>
0 siblings, 1 reply; 2+ messages in thread
From: yusuf0478@netscape.net @ 2003-10-23 18:17 UTC (permalink / raw)
To: pgsql-sql
I'm interested in finding the minimim A.id such that the following holds:
select A.charge
, B.user_id
, C.employee_id
from A
inner join B using (user_id)
inner join C using (employee_id)
except
select X.charge
, Y.user_id
, Z.employee_id
from X
inner join Y using (user_id)
inner join Z using (employee_id)
--
I can't do the following, since the number of selected columns have to match:
select A.id
, A.charge
, B.user_id
, C.employee_id
from A
inner join B using (user_id)
inner join C using (employee_id)
except
select X.charge
, Y.user_id
, Z.employee_id
from X
inner join Y using (user_id)
inner join Z using (employee_id)
Can someone help me with the query?
Thanks in advance.
__________________________________________________________________
McAfee VirusScan Online from the Netscape Network.
Comprehensive protection for your entire computer. Get your free trial today!
http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397
Get AOL Instant Messenger 5.1 free of charge. Download Now!
http://aim.aol.com/aimnew/Aim/register.adp?promo=380455
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Query Help using Except
2003-10-23 18:17 Query Help using Except yusuf0478@netscape.net
@ 2003-10-27 03:34 ` Bruno Wolff III <bruno@wolff.to>
0 siblings, 0 replies; 2+ messages in thread
From: Bruno Wolff III @ 2003-10-27 03:34 UTC (permalink / raw)
To: yusuf0478@netscape.net; +Cc: pgsql-sql
On Thu, Oct 23, 2003 at 14:17:08 -0400,
yusuf0478@netscape.net wrote:
>
> I can't do the following, since the number of selected columns have to match:
One option is to use where NOT EXISTS instead of EXCEPT. Another way would
be to add A.id to the rows in the set difference using a join. I expect the
second method would be slower and that you should try using NOT EXISTS.
>
> select A.id
> , A.charge
> , B.user_id
> , C.employee_id
> from A
> inner join B using (user_id)
> inner join C using (employee_id)
>
> except
>
> select X.charge
> , Y.user_id
> , Z.employee_id
> from X
> inner join Y using (user_id)
> inner join Z using (employee_id)
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-10-27 03:34 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-23 18:17 Query Help using Except yusuf0478@netscape.net
2003-10-27 03:34 ` Bruno Wolff III <bruno@wolff.to>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox