SQL BETWEEN Operator

The BETWEEN operator in SQL returns the values within the given range. The range can be text, number, or dates. The Between operators are inclusive which means the starting value and the ending values are included.

  • Syntax of BETWEEN Operator –

SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2;

 

Here, in the WHERE clause, we have added the between clause which has a range of values. The returned result will have the values that match the values in between value1 and value 2.

Demo Table – 

Product Table

Category

Region

City

Country

Customer_ID

Customer_name

Sales

Office Supplies

Central

Chicago

United States

SM-20950

Suzanne McNair

539.97

Technology

East

New York City

United States

AH-10465

Amy Hunt

22.58

Office Supplies

East

New York City

United States

AH-10465

Amy Hunt

16.52

Office Supplies

East

Dover

United States

EP-13915

Emily Phan

671.94

Office Supplies

East

Dover

United States

EP-13915

Emily Phan

169.064

Technology

West

Aurora

United States

TP-21565

Tracy Poddar

168.624

Office Supplies

West

Aurora

United States

TP-21565

Tracy Poddar

19.44

Office Supplies

East

Long Beach

United States

AR-10825

Anthony Rawles

31.92

Office Supplies

West

Pasadena

United States

HA-14920

Helen Andreada

433.568

Furniture

West

Pasadena

United States

HA-14920

Helen Andreada

31.104

Example – Consider the Product table of the Customer database where we want to get those customer names whose profit is between 100 to 1000.

SELECT DISTINCT Category,Region,City,Country,[Customer ID],[Customer Name],Sales FROM [dbo].[Products] WHERE Sales BETWEEN 100 AND 700;

 

The output after executing the above statement shows the customer’s names who have profits between 100 to 700 –

Category

Region

City

Country

Customer_ID

Customer_name

Sales

Office Supplies

Central

Chicago

United States

SM-20950

Suzanne McNair

539.97

Office Supplies

East

Dover

United States

EP-13915

Emily Phan

671.94

Office Supplies

East

Dover

United States

EP-13915

Emily Phan

169.064

Technology

West

Aurora

United States

TP-21565

Tracy Poddar

168.624

Office Supplies

West

Pasadena

United States

HA-14920

Helen Andreada

433.568

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

 Automate data analysis pipeline and create report ready dashboards

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