1

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

city table

enter image description here

country table

enter image description here

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.

Praveen
  • 55,303
  • 33
  • 133
  • 164
  • 2
    Why can you not use joins? Usually they are the best way. Also please do not post pictures of code or anything, post it as text. What have you tried? What is not working? – Brad Mar 18 '21 at 17:32
  • It is possible - using correlated subquery in WHERE. – Akina Mar 18 '21 at 17:32
  • You are comparing apples with pears. The output from `(SELECT Max(Population) FROM country WHERE Continent = 'Europe')` give the population for the biggest country in Europe, and you are comparing it to the population of a city. – Luuk Mar 18 '21 at 17:50
  • correlated subquery can be used as an alternative to join, – javapedia.net Mar 19 '21 at 02:32

2 Answers2

0

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
Akina
  • 39,301
  • 5
  • 14
  • 25
0

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