At 11:02 AM 5/30/01 , John McNally wrote:
>Florian Lindauer wrote:
> >
> > In your documentation, under "advanced peers" (now: peers howto)
> > - Examples, there is an example how to build a criteria for
> > a query like
> > select * from abc where (a < 1 and b > 2) or (a > 5 and b < 3)
> >
> > Doing just as is described, we find that the actual sql
> > built together is
> > ... where (a < 1) or (a > 5 and (b < 3)) and (b > 2)
> >
> > Now, I am quite sure this is not equivalent.
>
>It would appear to me that the two where clauses are equivalent. Can
>you explain why they are not?
>
>john mcnally
I'm undecided about the virtues or drawbacks of Florian's suggestion,
but I think he's correct that the two expressions are not equivalent.
The first expression:
(a < 1 and b > 2) or (a > 5 and b < 3)
is satisfied by a=6, b=1, while the second expression:
(a < 1) or (a > 5 and (b < 3)) and (b > 2)
is _not_ satisfied by a=6, b=1.
I don't recall what the precedence of "and" vs. "or" is in SQL,
but in this case, it doesn't matter. It's "false or true and false".
If the "and" binds tighter you get "false or (true and false)". If
the "or" binds tighter, you get "(false or true) and false". Either
way, the second expression is false, while the first is true.
Jeremy Leader
[EMAIL PROTECTED]
626-794-2145
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]