SQL OR Clause Example.
SQL OR Clause
The OR operator is used in SQL to combine multiple conditions in a WHERE clause. It allows the SQL query to fetch records if any of the conditions specified are true.
Example Usage of OR
Consider a database table named Employees with the following columns:
EmployeeID- An identifier for the employee.Name- The name of the employee.Age- The age of the employee.Department- The department where the employee works.
We want to find all employees who are either 30 years old or work in the 'Sales' department. The SQL query would look like this:
SELECT *
FROM Employees
WHERE Age = 30
OR Department = 'Sales';
Explanation of the Query
The query selects all columns from the Employees table where the Age is 30 or the Department is 'Sales'. The OR operator allows the query to fetch records satisfying either condition.
Comments
Post a Comment