Sunday, December 2, 2012

Useless combination of logical expressions

Recently I stumbled upon this SQL where clause :
status <> 2  OR status <> 0
or in equivalent form for you PHP developers :
(status != 2 )  || (status != 0)

To analyze why such combination are useless,
Lets define two variables to simplify things :

A = (status <> 0)
B = (status <> 2)

And draw it on one table :


 Then I wonder, what good does that do ? It always evaluates to true..
It only make sense if we combine the status comparisons with the and operator :

No comments: