SQL OR Operator in Where Clause with Example

  Total Views : 380
  Comments : 0
 
  Keywords : SQL or operator with example, OR operator in sql server with example, SQL or operator syntax with example, How to use sql or operator in where clause with example

Here we will learn or operator in sql with example, syntax of or operator in sql server and how to use sql operator in where clause with example.

SQL OR Operator

The OR operator in SQL is used to compare data with more than one condition. If either of condition is TRUE it will return data. Generally we will use this operator in WHERE clause and syntax for OR operator in SQL will be like as shown below 

Syntax of SQL OR Operator

Following sql statement is the syntax of OR operator in sql server

 

SELECT column1, column2 FROM tablename WHERE column1 ='somevalue' OR column2='Somevalue'

We will check this with example for that create “EmployeeDetails” table by using below script in sql database

 

create table EmployeeDetails(empid int, empname varchar(50),designation varchar(50),salary int,Location varchar(50))

 

insert into EmployeeDetails

values(1,'suresh','software engineer',25000,'chennai'),

(2,'rohini','AEO',15000,'chennai'),

(3,'madhavsai','business analyst',50000,'nagpur'),

(4,'mahendra','CA',75000,'guntur'),

(5,'sateesh','Doctor',65000,'guntur')

 

select * from EmployeeDetails

Once we run above sql script our table “EmployeeDetails” will create and result will be like as shown below

 

Newly created employeedetails table in sql server

Now run following examples to check OR operator in sql

SQL OR Operator Example 1

In following SQL query we are checking multiple conditions with OR operator. It will return records whatever it satisfy either of one condition or both conditions.

 

SELECT * FROM EmployeeDetails WHERE Location='guntur' OR Salary>40000

Once we run query our sql or operator result will be like as shown below

 

Output

 

Following is the result of sql or operator example

 

Result of sql sever or operator example

SQL OR Operator Example 2

In following SQL query we are checking multiple conditions (empname, salary) with OR operator. It will return records whatever it satisfy either of one condition or both conditions.

 

SELECT * FROM EmployeeDetails WHERE empname='rohini' OR Salary>40000

If we run above query our sql or operator result will be like as shown below

 

Output

 

Following is the result of sql or operator example

 

sql or operator example with where clause output or result

This is how we can use sql or operator in where clause.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User