MySQL

OR Operator in MySQL

In this tutorial, we are going to see how to use the OR operator in MySQL. The OR operator combines two Boolean expressions and returns true when one of the conditions is true.
 

Syntax:

The following syntax illustrates the use of the OR operator.

expression1 OR expression2

The two expressions “expression1” and “expression2” are boolean expressions that return true, false or NULL.
 

 

Example:

For example, to get the customers located in San Francisco or Boston , use the OR operator in the clause WHERE as follows:

SELECT * FROM Customers WHERE Address = 'San Francisco' OR Address = 'Boston';

Output:

+----------+-----------+--------+-----------------------+
|    ID    |    Name   |  Age   |     Address           |
+----------+-----------+--------+-----------------------+
|    101   |   Alex    |   25   | San Francisco         |
|    102   |   Emily   |   15   | San Francisco         |
|    103   |   Jean    |   35   | Boston                |
|    104   |   Bob     |   40   | Boston                |
+----------+-----------+--------+-----------------------+
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *