Friday, April 20, 2007

‘AND’, ‘OR’ and ()

Sometime we don’t care about brackets at right position, especially when giving conditional statement. I guess everyone has put himself in trouble at leas once just for this.
A simple example in SQL query (make sure that your table i.e. myTable contains some records),

select * from myTable where 1=1 and 0=0 or 1=1 and 1=2
select * from myTable where 1=1 and (0=0 or 1=1) and 1=2

And it becomes worse when output chagnes depending upon platform in case of statement without any brackets.

No comments: