IN and BETWEEN Operator in Oracle SQL | Oracle SQL Tutorials -15

Hi,

I will explain IN and BETWEEN Operator in Oracle SQL in this post of Oracle SQL Tutorial series.

Read the previous post of this tutorial series before this.

COUNT(), AVG() and SUM() Functions in Oracle SQL | Oracle SQL Tutorials -14

 

 

IN Operator

You can use multiple values in a WHERE clause via IN Operator.

You can use IN Operator in a WHERE Clause instead of multiple OR conditions.

 

 

IN Syntax

IN () operator syntax is as follows.

SELECT *  FROM table_name WHERE column_name IN (value1, value2, …);

SELECT column1,column2,.. FROM table_name WHERE column_name IN (value1, value2, ...);

IN operator examples are as follows.
SQL> select first_name,last_name,salary from hr.employees where manager_id IN (100,200,300);

FIRST_NAME           LAST_NAME                     SALARY
-------------------- ------------------------- ----------
Neena                Kochhar                        23000
Lex                  De Haan                        23000
Den                  Raphaely                       12000
Matthew              Weiss                           9000
Adam                 Fripp                           9200
Payam                Kaufling                        8900
Shanta               Vollman                         7500
Kevin                Mourgos                         6800
John                 Russell                        15000
Karen                Partners                       14500
Alberto              Errazuriz                      13000

FIRST_NAME           LAST_NAME                     SALARY
-------------------- ------------------------- ----------
Gerald               Cambrault                      12000
Eleni                Zlotkey                        11500
Michael              Hartstein                      14000

14 rows selected.

SQL> 

SQL> select first_name,last_name,salary from hr.employees where department_id in (20,30,40);

FIRST_NAME           LAST_NAME                     SALARY
-------------------- ------------------------- ----------
Michael              Hartstein                      14000
Pat                  Fay                             7000
Den                  Raphaely                       12000
Alexander            Khoo                            4100
Shelli               Baida                           3900
Sigal                Tobias                          3800
Guy                  Himuro                          3600
Karen                Colmenares                      3500
Susan                Mavris                          7500

9 rows selected.

SQL>

 

 

SQL> select first_name,last_name,salary from hr.employees where department_id IN ( select department_id from hr.employees where salary IN (23000,30000,40000));

FIRST_NAME           LAST_NAME                     SALARY
-------------------- ------------------------- ----------
Neena                Kochhar                        23000
Lex                  De Haan                        23000

SQL>

 

 

 

BETWEEN Operator

BETWEEN operator is used in the Where Clause and it is used to select values within a given range.

 

 

BETWEEN Syntax

BETWEEN syntax is as follows.

 

SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;

BETWEEN Operator examples are as follows.
SQL> 
SQL> select first_name,last_name,salary from hr.employees where department_id BETWEEN 100 AND 500;

FIRST_NAME           LAST_NAME                     SALARY
-------------------- ------------------------- ----------
Nancy                Greenberg                      13008
Daniel               Faviet                         10000
John                 Chen                            9200
Ismael               Sciarra                         8700
Jose Manuel          Urman                           8800
Luis                 Popp                            7900
Shelley              Higgins                        13008
William              Gietz                           9300

8 rows selected.

SQL> 
SQL> 
SQL>  select first_name,last_name,salary from hr.employees where salary between 15000 and 25000;

FIRST_NAME           LAST_NAME                     SALARY
-------------------- ------------------------- ----------
Neena                Kochhar                        23000
Lex                  De Haan                        23000
John                 Russell                        15000

SQL>


Do you want to learn Oracle SQL Tutorial for Beginners, then read the following articles.

Oracle SQL Tutorials For Beginners – Learn Oracle SQL from scratch with Oracle SQL Online Course

 401 views last month,  4 views today

About Mehmet Salih Deveci

blank
I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience. I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource. I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks. I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients. If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress mehmetsalih.deveci@outlook.com. -                                                                                                                                                                                                                                                 - Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  mehmetsalih.deveci@outlook.com a mail atabilirsiniz.

Check Also

blank

Create Table ( CTAS ) and Data Types, LOB Data Types in Oracle SQL | Oracle SQL Tutorials -27

Hi, I will explain Create Table ( CTAS ) and Data Types in Oracle SQL in …

Leave a Reply