Skip to content
Advertisement

Why are these 2 queries giving different outputs?

Query no 1:-

The Query 1 gives me the following output:-

Query no 2:-

The Query 2 gives me the following output:-

Advertisement

Answer

Summary: The AND operator has higher precedence than the OR operator. To fix it, use brackets around the OR expression.


AND has higher precedence than OR so your first query is the equivalent of (with added brackets and indentation to emphasise the precedence):

So you are finding either: managers with any salary; or analysts whose salary equals the salary plus commission of any other employee.

Your second query is the equivalent of:

Which finds: any employee who is either a manager or an analyst and whose salary equals the salary plus commission of any other employee.


You could rewrite your first query to:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement