Nesting queries in SQL

前端 未结 4 846
余生分开走
余生分开走 2020-12-28 20:11

The goal of my query is to return the country name and its head of state if it\'s headofstate has a name starting with A, and the capital of the country has greater than 100

4条回答
  •  我在风中等你
    2020-12-28 20:54

    The way I see it, the only place for a nested query would be in the WHERE clause, so e.g.

    SELECT country.name, country.headofstate
    FROM country 
    WHERE country.headofstate LIKE 'A%' AND 
    country.id in (SELECT country_id FROM city WHERE population > 100000)
    

    Apart from that, I have to agree with Adrian on: why the heck should you use nested queries?

提交回复
热议问题