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!

Include multiple range in one query

SHUBHMay 21 2015 — edited May 21 2015

I have a table

Tew which has multiple rows like( for a branchid, user has maintained multiple ranges of accounts )

Branch id         Low  High Account_Range

100                  80     95     80-95

100                  100   110   100-110

100                  150    155   150-155

Create table tew(Branchid varchar2(10),        Low number , High number,  Account_Range varchar2(30));

insert into tew values(100,80,95,'80-95');

insert into tew values(100,100,110,'100-110');

insert into tew values(100,150,155,'150-155');

It means that for Branch id 100, I have all these ranges applicable for accounts( Any account that is in between these ranges should be processed and anything not in range ignored).

One way is to have three different queries and joining them by union

But I would like to combine all the different account ranges into one query.

Something similar to

Select '1' from tew where branchid =100 and ((account_range between 80 and 90 )or( account range between 100 and 110) or( account_range between 150 and 155))

I am going to retrieve account from another table and this table would be used to validate if for that brancid , the account falls in the range or not. If it falls in range it would be processed else it would be ignored.

Is there a better way of doing this ?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 18 2015
Added on May 21 2015
2 comments
267 views