The OR operator is used with SQL WHERE clause. The OR operator is used to filter data based on one or more condition.
Syntax using OR operator
SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 ...
Example using SQL AND operator
Find out all the customers of BIHAR state and also from HARYANA from the Cusotmer Table
SELECT * FROM Customer WHERE CUSTSTATE = 'BIHAR' OR CUSTSTATE = 'HARYANA'
CUSTID CUSTNAME CUSTCITY CUSTSTATE CUSTCOUNTRY 1 Amit PATNA BIHAR INDIA 2 Anil PATNA BIHAR INDIA 3 Dhanraj HISAR HARYANA INDIA
Combining AND/OR operator
We can use both AND and OR operator in the single WHERE clause.
Find out all the customers of Country INDIA and City either CHENNAI or HISAR from the Cusotmer Table
SELECT * FROM Customer WHERE CUSTCOUNTRY ='INDIA' and ( CUSTCITY = 'CHENNAI' or CUSTCITY = 'HISAR')
CUSTID CUSTNAME CUSTCITY CUSTSTATE CUSTCOUNTRY 3 Dhanraj HISAR HARYANA INDIA 8 Annamalai CHENNAI TAMIL NADU INDIA 9 Kannan CHENNAI TAMIL NADU INDIA