Praveen Rawat Praveen Rawat - 1 year ago 54
SQL Question

Does second conditions check, if first condition found false in multiple AND-Conditions for a record in SQL?

if we have multiple AND conditions in where clause of a SQL query and if first condition found false for a records then will it goes to check for another AND condition or not.

in programming we use && operator to check the multiple condition where if first condition found false then it does't goes for another condition, So my query is is it also applies in SQL conditions?


Select * from tablename where column is not null and column > 0 and column <> 1

Answer Source

SQL is declarative. Not procedural.

The optimiser may use short circuit evaluation or may not.

It also may convert that to something different. If column is integer type all three conditions collapse to

WHERE column > 1

Similarly the optimiser might find some conditions are guaranteed to be true or false by check constraints or other predicates in the query and don't need evaluating at all. Or use an access path (such as filtered index) that guarantees all rows match a part of the predicate so no run time evaluation is needed.