Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: Conjunction junction

Re: Conjunction junction

From: Alan <alan_at_erols.com>
Date: Mon, 1 Nov 2004 13:00:46 -0500
Message-ID: <2unbuhF2cbaliU1@uni-berlin.de>

"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. 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. Received on Mon Nov 01 2004 - 12:00:46 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US