SQL OR Operators

The OR operator displays records if any of the conditions is true.

SQL OR Operators

SQL OR Operators

     

The OR operator displays records if any of the conditions is true.

1st Condition 2nd Condition Result
false false false
false true true
true false true
true true true

Understand with Example

The Tutorial illustrate an example from SQL OR Operator .In this we help you to know the use of  'OR' Operator. For this we create a table Stu_Table with the help of create statement.  

Create Table Stu_Table

create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), Stu_Class  varchar(10))

Insert data into Stu_Table

The insert into add the records or rows to the table Stu_Table.

insert into Stu_Table values(1,'Komal',10);
insert into Stu_Table values(2,'Ajay',10);
insert into Stu_Table values(3,'Rakesh',11);
insert into Stu_Table values(4,'Bhanu',11);
insert into Stu_Table values(5,'Santosh',12);
insert into Stu_Table values(1,'Komal',10);

Stu_Table

The select statement help you to display the table detail.

Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 11
4 Bhanu 11
5 Santosh 12
1 Komal 10

SQL OR Operator Syntax

The SQL OR Operator is used to return a record if either the first condition is true or the second condition is true. The Syntax used for SQL OR Operator is given below:

SELECT columnName(s)
FROM tableName
where condition1 OR conditions2

SQL OR Operator Query

In this example, we make use of OR Operator, which return the records from a table on the basis of  condition in WHERE Clause. The OR Operator  return you a set of records,if either of the condition are true.  

SELECT Stu_Id, Stu_Name, Stu_Class
FROM Stu_Table
where Stu_Id = 1 OR Stu_Class = 10

Result

Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
1 Komal 11