Im using Oracle PLSQL. Im trying to make a join beetween two tables and make a filter from one parameter that can be 'W' (Woman) or 'M' (Man).
I have this table with a list of Jobs:
And this other one with every job translated to English or Spanish for each gender:
I want to get the job translated to both languages for the gender specified in the parameter. If there is no translation for Woman, then get translation for Man.
I tried to do this with NVL but it's not working:
select j.*, l.long_name, l.language, l.gender
from job j
join job_lang l
on j.id = l.id_job
where j.short_name = 'Firefighter'
and nvl(l.gender, 'M') = 'M'; -- parameter
It works perfect when the parameter is 'M' but returns nothing when is 'W' because there is no translation for Woman.
I'm not sure if I can do this with a case, I tried but I couldn't find anything. Could you help me?
Thanks.
You could use the
fetch
clause with window functions for prioritization: