Skip to main content
formatting
Source Link
Andriy M
  • 23.2k
  • 6
  • 59
  • 103

SQL/PDO how to select both the countries list from the Select countries table and a countcounts of people in thatper country from another table

i know the title might be kinda hard to understand, i didint knew how to put it.

Anyway iI have 2 tables, one is a list of countries (idid,country country) and another is the users (where the 'country'country column is the 'id'id of the country in the 'countries'countries table).

Is it possible to make a single query that returns both the country name and the count of people who has that country 'id'id in their countrycountry column?

like 'country':'uk', 'users':4; 'country':'portugal', 'users':2; 'country':'usa', 'users':10; ...

Thanks

country   users
--------  -----
uk        4
portugal  2
usa       10
...

SQL/PDO how to select both the countries list from the countries table and a count of people in that country from another table

i know the title might be kinda hard to understand, i didint knew how to put it.

Anyway i have 2 tables, one is a list of countries (id,country) and another is the users (where the 'country' column is the 'id' of the country in the 'countries' table).

Is it possible to make a single query that returns both the country name and the count of people who has that country 'id' in their country column?

like 'country':'uk', 'users':4; 'country':'portugal', 'users':2; 'country':'usa', 'users':10; ...

Thanks

Select countries and counts of people per country

I have 2 tables, one is a list of countries (id, country) and another is the users (where the country column is the id of the country in the countries table).

Is it possible to make a single query that returns both the country name and the count of people who has that country id in their country column?

like

country   users
--------  -----
uk        4
portugal  2
usa       10
...
Source Link
Ruben
  • 1
  • 1
  • 1

SQL/PDO how to select both the countries list from the countries table and a count of people in that country from another table

i know the title might be kinda hard to understand, i didint knew how to put it.

Anyway i have 2 tables, one is a list of countries (id,country) and another is the users (where the 'country' column is the 'id' of the country in the 'countries' table).

Is it possible to make a single query that returns both the country name and the count of people who has that country 'id' in their country column?

like 'country':'uk', 'users':4; 'country':'portugal', 'users':2; 'country':'usa', 'users':10; ...

Thanks