SQL Parentheses use in an OR clause

Take a look at the Operator Precedence in SQL Server (You’ve not specified that, but I’d imagine it’s the same for all RDBMS). What this means is that ANDs (without parenthesis) are evaluated before1 bind more tightly than ORs.

So in your specific case, without the parenthesis, the conditions are:

  • employe.service=service.code_serv AND employe.nom LIKE 'A%'

OR

  • employe.nom LIKE 'B%'

1Evaluation order is deliberately not specified in SQL, allowing many more possible re-orderings that languages that guarantee left-to-right or precedence ordered evaluation.

Leave a Comment