Skip to content
Advertisement

Select field based on other column max value in oracle pl/sql

I am calculating a field called “Degree Level” in a view. This is a field in the table “Degrees”, and the table shows degrees for each faculty member. A faculty member can have more than one degree.

The field “degree level” is also in the table “Crosswalk_Table”. I want to choose Degree level for a faculty member based on the max value in the column “Degree_Hierarchy” in the Crosswalk_table.

The code below displays the “Master” instead of the “Doctor” for degree level (which has the higher hierarchy value). ANY help is much appreciated thank you.

Sample Data:

Degree table:

Crosswalk_Table:

Advertisement

Answer

If you are using Oracle 12 or higher, then you may use a subquery like that (with ORDER BY and LIMIT to 1 row):

Please take a look at this simple demo: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=c8d41924c593f4f361de59a611a363cc

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement