1

This does not belong to any specific language, but logic. I just use SQL as an example: I have 2 clauses:

(1) WHERE A1 AND A2

(2) WHERE A1 OR A2

In the (1) case, would query stop right after checking A1 is false? In the (2) case, would query stop right after checking A1 is true?

Please mark this one as duplicated if someone asked before.

Thank you

Jerry Stratton
  • 3,287
  • 1
  • 22
  • 30
Einsamer
  • 1,069
  • 4
  • 17
  • 34

2 Answers2

6

You have the wrong idea. SQL queries represent the result set, not the processing that takes place. So, the where clause does not represent a specific set of instructions. The clauses can be executed in any order.

That said, most databases do short-circuit such evaluations. So execution usually stops with the first clause that determines the condition (true or false).

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
2

What you're describing is called "short-circuiting", and I'm sure it varies by language, but I know JavaScript and ColdFusion both behave the way you describe.

SQL is implementation dependent:

https://stackoverflow.com/a/909770/2913684

Community
  • 1
  • 1
Robert Caldwell
  • 89
  • 1
  • 1
  • 5