Nesting queries in SQL

Posted by ZAX on Stack Overflow See other posts from Stack Overflow or by ZAX
Published on 2012-09-17T21:28:16Z Indexed on 2012/09/17 21:38 UTC
Read the original article Hit count: 223

Filed under:
|
|

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,000 people utilizing a nested query.

Here is my query:

SELECT country.name as country, 
       (SELECT country.headofstate 
        from country 
        where country.headofstate like 'A%')      
from country, city 
where city.population > 100000;

I've tried reversing it, placing it in the where clause etc. I don't get nested queries. I'm just getting errors back, like subquery returns more than one row and such. If someone could help me out with how to order it, and explain why it needs to be a certain way, that'd be great.

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql