SQL OR Operator

The OR operator is used to operate multiple statements in the WHERE clause. The results are returned when anyone conditions mentioned within OR Operator are true. These operators are used to combine multiple statements in SQL.
  • Syntax of OR Operator

SELECT column1,column2,column3,...,columnN FROM table_name WHERE condition1 OR condition2....OR conditionN

Here, as in the syntax shown, in the WHERE clause, we can add N number of conditions. To get the result, it’s necessary to get any one condition to be TRUE. Unlike SQL AND Operators, in OR if any condition is not true then the matching is done on another condition.

Demo table –

Product Table 

Category Region City Country Customer_ID Customer_name
Office Supplies Central Chicago United States SM-20950 Suzanne McNair
Technology East New York City United States AH-10465 Amy Hunt
Office Supplies East New York City United States AH-10465 Amy Hunt
Office Supplies East Dover United States EP-13915 Emily Phan
Office Supplies East Dover United States EP-13915 Emily Phan
Technology West Aurora United States TP-21565 Tracy Poddar
Office Supplies West Aurora United States TP-21565 Tracy Poddar
Office Supplies East Long Beach United States AR-10825 Anthony Rawles
Office Supplies West Pasadena United States HA-14920 Helen Andreada
Furniture West Pasadena United States HA-14920 Helen Andreada
Example – Consider the Product table of the Customer database where we want to get those customer names that belong to the City of Chicago or New York City.

SELECT [Customer Name],City FROM [dbo].[Products] WHERE City = 'Chicago' OR City = 'New York City';

The output after executing the above statement is as shown –
Category Region City Country Customer_ID Customer_name
Office Supplies Central Chicago United States SM-20950 Suzanne McNair
Technology East New York City United States AH-10465 Amy Hunt
Office Supplies East New York City United States AH-10465 Amy Hunt

Other SQL topics to check out:

Follow us on TwitterFacebook, Linkedin, and Tableau Public to stay updated with our latest blog and what’s new in Tableau.

If you are looking forward to getting your data pipeline built and setting up the dashboard for business intelligence, book a call now from here.

#analytics #data #business #artificialintelligence #machinelearning #startup #deeplearning #deeplearning #datascience #ai #growth #dataanalytics #india #datascientist #powerbi #dataanalysis #tableau #SQL #businessanalytics #businessanalyst #businessandmanagement #dataanalyst #businessanalysis #analyst #analysis #powerbideveloper #powerbidesktop #letsviz