MYSQL: OR Operator

Profile picture for user arilio666

The OR operator in MySQL is another type of operator which has its unique attribute towards the operation goal. AND operator satisfies both the conditions then it returns true that is the purpose of AND. Both have to return a true value.

In the case of the OR operator, any one of the conditions provided can satisfy the query meaning out of two conditions provided whichever returns the true value returns and if the other one fails to return true it doesn't matter.

Syntax

SELECT * from TableName WHERE condition1 (comparison) condition2 OR condition3 (comparison) condition4

Lets us see a real-time example that involves the customer's table which we used for AND operator article we will slightly perform a condition based on OR

So this is what we will do today:

  1.   Select the customer's table.
  2.   We are gonna query the table based on the conditions of birthdate greater than 1990 should OR points greater than 500 and customer from state 'VA'(Virginia)

Example:

select * from customers where birth_date > '1990-01-01' OR points > 500 and state = 'VA'

  • So as we can see here we are facing 2 OR scenarios.
  • The first row and the third row where the birthdate for the first row is not greater than 1990 it is less but the state condition and points condition satisfied and in the third row the points are less and the state is also not from 'VA' but the birthdate condition of greater than 1990 was satisfied.
  • So this is OR operator where any one of the conditions gets satisfied as long it is true in one side.
Tags