Select city in Continent = 'Europe' with Max Population but without using Joins (MySQL)

cqoc49vn  于 2022-12-22  发布在  Mysql
关注(0)|答案(2)|浏览(141)

I'm learning to write SQL queries in MySQL Workbench. At this moment I have two tables:

city table

country table

Is it possible to SELECT name of city With MAX population from city table which are in Continent of 'Europe', but without using Joins? (only using nested SELECT and Max() function)
Can't figure out how to work with two tables at the same time.

mzaanser

mzaanser1#

Schematically (adjust names):

SELECT city_name
FROM cities
WHERE 'Europe' = ( SELECT continent_name
                   FROM countries
                   WHERE cities.country_id = countries.id )
ORDER BY population DESC LIMIT 1
xqk2d5yq

xqk2d5yq2#

SELECT Name FROM cities WHERE CountryCode IN ( SELECT Code FROM countries WHERE Continent = 'Europe') group by Name, countrycode having max(population)

相关问题