Re: Conjunction junction

From: Tony Andrews <andrewst_at_onetel.com>
Date: 1 Nov 2004 12:19:50 -0800
Message-ID: <1099340390.751573.125250_at_c13g2000cwb.googlegroups.com>


Alan wrote:
> "Tony Andrews" <andrewst_at_onetel.com> wrote in message
> news:1099323627.582136.287610_at_c13g2000cwb.googlegroups.com...
> > Alan wrote:
> > > The OR _should_ work like an XOR:
> > >
> > > SELECT stock_location
> > > FROM pennants
> > > WHERE color = 'red' XOR color = 'green' XOR color = 'yellow'
> > >
> > > This would return one row, namely, the first one it finds of any
of
> > these
> > > colors.
> >
> > No it would not, it would still return all of them, because no row
has
> > color='red' AND (color='green' or color='yellow') or any of the
other
> > combinations. To demonstrate XOR you need at least 2 attributes:
> >
> > SELECT stock_location
> > FROM pennants
> > WHERE color = 'red' XOR size = 3 XOR shape = 'square';
> >
> > This would return pennants that are red but NOT size 3 or square,
and
> > pennants that are size 3 but NOT red or square, or square but NOT
red
> > or size 3.
> >
> > But you are right that XOR should be part of SQL.
> >
>
>
> What you described is two operators, OR <>, and of course we have
that.

Yes, and it is known in logic as the "exclusive OR", with a standard abbreviation of XOR.

> The XOR I am after would behave the way I described, which is exactly
> sematically opposite of the AND operator we have. A use for this came
up
> recently in another NG, and it is what got me thinking about it. The
OP
> wanted to query a UNION of two databases, A and B, but wanted to stop
as
> soon as the results were found in A or found in B, thereby avoiding
the
> UNION. Of course this can be done procedureally, but the XOR I
described
> would have allowed it in straight SQL. Maybe call it an IOR
(Immediate OR)
> if XOR is confusing.
>
> SELECT *
> FROM A, B
> WHERE a.pk = b.pk
> AND a.color = 'red' XOR b.color = 'red'
>
> IOW, if you find it in A, don't look in B, and vice-versa.

Yes, you would need to use a different name because that is not what XOR means. What you are looking for is a quota ("TOP 1" in some SQL flavours), not a logical operator at all. Received on Mon Nov 01 2004 - 21:19:50 CET

Original text of this message