Re: Conjunction junction

From: Alan <alan_at_erols.com>
Date: Mon, 1 Nov 2004 10:09:45 -0500
Message-ID: <2un1tqF2bo5daU1_at_uni-berlin.de>


> But what I want to get to is this: why do DB designers have more trouble
> with disjunction than with conjunction?
> Or to put it another way: why do they have more problems with
> generalization-specialization hierarchies than they do with intersection
of
> sets and equijoins? To put it yet another way, why does OR bother
database
> designers more than AND?
>

Because they are not implemented the same way. They are not the inverse/converse? of one another as one would expect.

The AND operator is really an ANDALL, meaning _all_ conditions of the AND must be met. This is fine. The OR operator, however is not the complete semantic opposite of the AND, it is only partially so. The exact opopsite would be an XOR, the Exclusive OR. Easiest to explain by example:

Given a table of solid colored pennants: pennant_name
color
size
stock_location

I need to show a pennant to a kindergarten class. I want the color to be either red or green or yellow. I don't care which one, I just want one of these bright, primary colors. So my SQL is:

SELECT stock_location
FROM pennants
WHERE color = 'red' OR color = 'green' OR color = 'yellow'

Unfortuntely, this will return all rows where the pennants are red or green or yellow. I just want one, not all of them.

Okay, let's try the AND operator instead:

SELECT stock_location
FROM pennants
WHERE color = 'red' AND color = 'green' AND color = 'yellow'

This returns no rows, because pennants are only one color, not three colors. All three conditions are not met.

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.

So, getting back to semantic opposites:

AND must meet _all_ and always all conditions, so, OR _should_ only need to meet _one_ and only one condition to be the semantic opposite of AND.

The worst part is, we don't even have an XOR in SQL. Received on Mon Nov 01 2004 - 16:09:45 CET

Original text of this message