Skip to content
Advertisement

How to overcome the problem. If manager is not available then display manager name ‘NA’. If phone number is not available then display as ‘NA’

I have written the query like:

1 select resort.resortid,resort.resortname,nvl(manager.name,'NA')MANAGERNAME,
2 nvl(manager.phone,'NA')PHONENO 
3 from 
  resort join manager on resort.managerid=manager.managerid
4 order by resort.resortid;

Problem is, I’m not getting the output containing null values

Advertisement

Answer

A regular (inner) join will only return rows that match the join condition. You’re looking for a left join:

SELECT    resort.resortid,
          resort.resortname,
          NVL(manager.name,'NA' ) managername,
          NVL(manager.phone,'NA') phoneno
FROM      resort 
LEFT JOIN manager ON resort.managerid = manager.managerid
ORDER BY  resort.resortid;
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement