Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Obtaining a range of department ids using BETWEEN operator

buggleboy007May 17 2022

I have an issue where in I want to retrieve departments from 10 to 80 and then department 200. 
The department table's is as follows:
Capture1.JPG (142.56 KB)
I know I can use the IN operator but I do not want to use IN operator instead use BETWEEN operator. However BETWEEN (only 2 ranges) works well for 10(1st range) to 80 (2nd range). But when it comes to 200 how can I use it? 
I have approached the issue the following way using UNION ALL operator:

select department_id, department_name, manager_id, location_id
from t1_departments t1
where t1.department_id between 10 and 80
UNION all
select department_id, department_name, manager_id, location_id
from t1_departments t
where t.department_id = 200;

The output is (which appears OK to my eye):
Capture1.JPG (109.99 KB)My question is:
a) is my approach correct?
b) if not is there a better way to do it?

This post has been answered by L. Fernigrini on May 17 2022
Jump to Answer
Comments
Post Details
Added on May 17 2022
18 comments
1,252 views