On this page http://sqlzoo.net/1a.htm there is a question that asks me to show the names of all the countries in Europe that have a GDP per capita that is greater than the UK.
I have so far:
Here's how to list the countries in Europe
select name from bbc where region = 'europe'
Here's how to show the GDP per captia of the UK
select name, gdp/population from bbc where name = 'united kingdom'
So using these two statements, I tried nesting them together like this:
select name from bbc where gdp/population IN (select name, gdp/population from bbc where region = 'europe') >
(select name, gdp/population from bbc where name = 'united kingdom')
and the error message I got says: sql: errorOperand should contain 1 column(s)
I can't seem to properly nest these select queries together and I believe it's due to an error in my syntax. Can someone show me how to put this together?
I just tried that out and it works perfectly! Thanks for helping me with the syntax and formatting!
let me explain the error first, before making suggestions to fix it
when you use this construction...
[WHERE] [I]expression[/I] IN ( [I]subquery[/I] )
you must be sure that the subquery returns only one column, so that the expression, which is a single value, can be compared to these individual column values, looking for a match
your subquery returns two columns
try this instead --
WHERE region = 'europe'
AND gdp/population =
( SELECT gdp/population
WHERE name = 'united kingdom' )
note the use of AND in the WHERE clause, to combine two conditions
you should also learn to use formatting in your code, with line breaks and indentation -- you will thank me later