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!

Easy way to filter to one row in order of value preference?

HRIS_noviceOct 18 2019 — edited Oct 19 2019

Employees may have any number of phone numbers (or none) listed in our database.  I would like an easy way to filter the query rows down to only one phone number per employee, based on a preferential list of phone types:

H1

HM

H2

WM

W1

W2

A

B

C

X

Y

Z

In other words, if they have an "H1" PHONE_TYPE, I'd like to get that PHONE_NUMBER.  If not, my second choice would be their "HM" phone number, if they have one.  Otherwise, I'll go down the list and take whatever they've got next.

If they don't have any phone listed, I'd like to return a literal "none".

I'm pretty new at SQL queries and not sure if this should be some kind of CASE in the SELECT clause or what.  Simpler is better for me right now.

Thanks!

Comments
Post Details
Added on Oct 18 2019
9 comments
3,098 views