Skip to content
Advertisement

Sql join in two tables and return empty tab as Unavaliable

In a SQL join, table 1 contains person info with city and table 2 contains city matched to country such as:-

Table #1

Table #2

I want to get the person ID, Name, Country so while joining the tables I want these items and if there is no country available for a city, I want “Unavailable” written in the country columns. Thanks

Advertisement

Answer

Try the below using left join and use coalesce() function to replace null country as ‘Unavailable’

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