Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7083657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:12:18+00:00 2026-05-28T07:12:18+00:00

I am new to SQL. Currently, I am learning to write complex queries. I

  • 0

I am new to SQL. Currently, I am learning to write complex queries.

I have three tables.
Country– has list of country

-----------+-------------
 CountryId | CountryName
-----------+-------------
         1 | India
         2 | Srilanka
         3 | Pakistan
         4 | Bangladesh
         5 | Nepal
         6 | America
         7 | Japan
         8 | China
         9 | Russia
        10 | Canada
        11 | Australia
---------------------------------------

city – list of cities of country

--------+-------------+-----------
 CityId | CityName    | CountryId
--------+-------------+-----------
      1 | Chennai     |         1
      2 | Washington  |         6
      3 | Moscow      |         9
      4 | Tokyo       |         7
      5 | Beijing     |         8
      6 | Sydney      |        11
      7 | Bangalore   |         1
      8 | Nagercoil   |         1
      9 | AmericaCity |         6
     10 | Kathmandu   |         5
     11 | Dhaka       |         4
     12 | Lahore      |         3
--------------------------------------

Airport – list of airports in a city

 AirportId | AirportName | CityId
-----------+-------------+--------
         1 | Airport1    |      1
         2 | Airport2    |      4
         3 | Airport3    |      5
         4 | Airport4    |      1
         5 | Airport5    |      6
         6 | Airport6    |      3
         7 | Airport7    |      5
         8 | Airport8    |      7
         9 | Airport9    |      6
        10 | Airport10   |      3
        11 | Airport11   |     11
        12 | Airport12   |     10
        13 | Airport13   |     12
---------------------------------

Question: I want to retrieve all the countries with number of airports, like

Output:
countryName Airports
India            3
Srilanka         0
......... etc.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:12:19+00:00Added an answer on May 28, 2026 at 7:12 am

    Try:

    SELECT
      Country.CountryId,
      Country.CountryName,
      count(AirportID) AS Airports
    FROM 
      Country
      LEFT JOIN city ON Country.CountryId=city.CountryId
      LEFT JOIN Airport ON city.CityId=Airport.CityId
    GROUP BY Country.CountryId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to SQL, so this isn't too complicated. I have two tables, with
I am new to SQL Server and currently learning it. I got following stored
I am currently using SQL Server Management Studio (Ver 9.00.3042.00) and click the New
I am writing some new SQL queries and want to check the query plans
I am totally new to SQL . I have a simple select query similar
I'm currently implementing a new functionality to a tool in an e-learning platform. I
Learning php! I have a sql database which contains a table called 'images' which
I have a fairly complex procedure that currently takes about 1:30 (min:sec) to complete.
Hey. I'm currently learning to use MySql and have a couple of questions. 1)
We are currently using SQL Server 2005. We don't need the new features in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.