In SQL, the OR operator is useful for comparing data with more than one condition, and it will return records when either of the conditions is TRUE.
Generally, we will use this operator in the WHERE clause, and the syntax of the OR operator in SQL will be like as shown below.
Following is the syntax of defining an OR operator in the SQL server.
We will check this with an example. Create an “EmployeeDetails” table by using the following script in the SQL database.
Once we run the above SQL script, the “EmployeeDetails” table will create and return the below result.
Now run the following examples to check OR operator in the SQL server.
In the following SQL query, we check multiple conditions with the OR operator. It will return records that satisfy either of one condition or both conditions.
When we execute the above OR operator example, we will get the below result.
In the following SQL query, we check multiple conditions (empname, salary) with the OR operator. It will return the records that satisfy either one condition or both conditions.
When we execute the above OR operator example, we will get the result below.
This is how we can use OR operator in the SQL server based on requirements.