In the previous article, we learn how to use AND operator. In this post, we will learn when and how to use SQL OR operator.
SQL OR is a logical operator. Like AND, SQL OR operator is used when we need to filter records on more than one condition. But unlike AND operator, a table record will be displayed, if any of the conditions separated by the OR operator returns true.
SQL OR Syntax
Select column1, column2,... columnN from table_name WHERE condition1 OR condition2;
Sample Table
Employee
Example
- Select all records from Employee table where salary is greater than 55000 or age is greater than 32
SELECT * FROM Employee WHERE SALARY > 55000 OR AGE > 32;
- Select all records from Employee table where salary is greater than 55000 or age is greater than 32 or designation is SDE I
SELECT * FROM Employee WHERE SALARY > 55000 OR AGE > 32 OR DESIGNATION = 'SDE I';
Hope you liked the article. If you have any doubts or concerns, please feel free to write us in comments or mail us at admin@codekru.com