OR Operator MySQL Essential Training

OR Operator MySQL Essential Training

MYSQL

OR Operator MySQL Essential Training




In our previous lesson we’ve been looking about the AND operator functionalities in various situations. So far we’re learn OR Operator MySQL Essential Training in this lesson. OR operator is an another logical operator which is performed based on the boolean expressions we’ve given. Lets Jump into the lesson, and see what it has for as.
The following illustrates the syntax of the OR operator.

The boolean_expression_1 and boolean_expression_2 are Boolean expressions that may return true, false, or NULL.
The following table shows the result of the OR operator.
OR Operator MySQL Essential Training
MySQL OR short-circuit evaluation
MySQL uses short-circuit evaluation for the OR operator. In OR Operator MySQL Essential Training other words, MySQL stops evaluating the remaining parts of the statement when it can determine the result.
See the following example.

OR Operator MySQL Essential Training
Because the expression 1 = 1 always returns true, MySQL does not evaluate the 1 / 0. If it did, it would issue an error message because of the division by zero error.
In our PHP Essential Training we learned about the Operator Precedence. It means when we have more than one logical functions and choose which runs first and which is second.
Operator Precedence
In OR Operator MySQL Essential Training when you use more than one logical operator in a statement, MySQL evaluates the OR operators after the AND operators. This is called operator precedence.
The operator precedence determines the order of evaluation of the operators. MySQL evaluates the operator with the higher precedence first.




See the following example.

OR Operator MySQL Essential Training
In this block we explain how it works in various situations:
1. First MySQL evaluates the values inside the Parenthesis (true or false) and returns true.
2. Then it tries to run the remaining part of the statement which is we have true in one hand and the false, then it returns the value as false.

OR Operator MySQL Essential Training

We use the emp_details table in the sample database for the demonstration.
For example, to get the employees who locate in the USA and India, you use the OR operator in the WHERE clause as follows:

OR Operator MySQL Essential Training
In the above example the query shows the employees who are located in USA and India.
We already said we can have the operator precedence can done with OR operator. So we use this with the AND operator to run some complicated tasks.

OR Operator MySQL Essential Training
Notice that if you do not use the parentheses, the query returns the employees who locate in the USA or the employees who locate in France with the credit limit greater than 15000.

OR Operator MySQL Essential Training
In OR Operator MySQL Essential Training the last example we can see the operator precedence how gives the different result in real time example.
This lesson will gives you an clear idea about how the OR operator functions in various conditions.




Leave a Reply