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;

OR Operator Example 1

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';
OR Operator Example 2

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';
OR Operator Example 3

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'.


ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.