SQL queries :set 2

By | April 25, 2014

Given 2 tables Country and City as shown below:
Country (countryid, countryname )
City (countryid, cityname )

1. Write a SQL query to find the countries that has no cities?
This can be easily solve using left outer join

2. Write a SQL query to find the countries that has less than 5 cities and also make sure the countries with no cities also show up?

We can use left outer join combined with count function to solve this.

Leave a Reply

Your email address will not be published. Required fields are marked *