Home »
MySQL
MySQL OR Operator
MySQL | OR Operator: Learn about the MySQL OR Operator, with its explanation, syntax, and query examples.
Submitted by Apurva Mathur, on September 12, 2022
OR Operator
We know how OR operator works, if any one of the values is the true result is true, if both the values are true result is true and if both the values are false then only the result will be false, so here also it works the same.
OR Operator Syntax
SELECT column_name1, column_name2, ...
FROM table_name
WHERE condition1 OR condition2;
Let us see some examples;
OR Operator Examples
Suppose we have a table named "student_details" and inside that table, we have the following columns;
Case 1: Suppose we want to know the names of the student whose year is either 3 or department is "ME", in such case since it is not compulsory that both the condition must be followed so here we can use OR condition,
SELECT * FROM student_details
WHERE year='3' OR student_department='ME';
Here the condition written is year='3' OR student_department="ME", which means all the students in 3rd year will be displayed also according to the second condition all the student studying in "ME" will be also displayed as the OR operator is there between them.
Case 2: Suppose we want to know the details of the students whose year is 2 or department is "Chemical" or the gender is "Female";
SELECT * FROM student_details
WHERE year='2' OR student_department='Chemical' OR gender='Female';
As the condition says year=2 OR student_department="Chemical" OR gender='Female', the result displayed has students from 2nd year also students who have "Chemical" branch and also the students who have gender='Female'.