OR condition in MYSQL by R4R Team

MYSQL OR condition:
Basically, We use OR operator when there is more than one condition but all are individual from each other.
-OR is used with select,insert,delete command.

Syntax:
WHERE condition1 OR conditions2...

Display all record of table employee:

SELECT * FROM employee;

emp_id emp_name department emp_salary
1 Aman D1 34000
2 Ram D2 43000
3 Ramesh D1 20000
4 John D3 65000
5 Sita D1 10000
6 Dinesh D2 15000


Now we display the employee detail who belongs to department D1 or D2.

SELECT * FROM employee WHERE department=D1 AND department=D2;

emp_id emp_name department emp_salary
1 Aman D1 34000
2 Ram D2 43000
3 Ramesh D1 20000
5 Sita D1 10000
6 Dinesh D2 15000


-In this Query we use OR between two conditions. so we get the result when any of one condition is True.



Leave a Comment: