A
A
Alex2018-10-11 20:15:19
SQL
Alex, 2018-10-11 20:15:19

Is the SQL query built correctly?

Greetings! Just started learning SQL. Ask for help from experts.
Given 2 tables:
- table gorod with fields: id, city_name, region_id, naselenie;
- region table with fields: id, region_name;
Write a query that allows you to determine the number of cities that is stored in the gorod table for each region, i.e. the result should be in the form: name of the corresponding region / number of cities. Here is my version:
SELECT region.region_name, COUNT(gorod.city_name)
FROM region INNER JOIN gorod
WHERE region.region_id = gorod.region_id
GROUP BY region.region_name;
Tell me, please, does this happen or do you need ON instead of WHERE?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nozzy, 2018-10-11
Gutter

SELECT region.region_name, COUNT(gorod.city_name) 
FROM region INNER JOIN gorod 
ON region.region_id = gorod.region_id
GROUP BY region.region_name;

A
ApeCoder, 2018-10-12
@ApeCoder

For INNER JOIN WHERE is equivalent in behavior to ON

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question