Reputation: 305
List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.
From https://sqlzoo.net/wiki/SELECT_within_SELECT_Tutorial, question 3
This is what I tried
select name, continent
from world
where continent = (select continent
from world where name in ('Argentina',' Australia'))
order by name
Thought it was about equivalence, so tried this
select name, continent
from world
where continent in (select continent
from world where name in ('Argentina',' Australia'))
order by name
and this seems to be the solution
select name, continent
from world
where continent = (select continent
from world where name ='Argentina')
or continent = (select continent
from world where name ='Australia')
order by name
I'm trying to understand the logical flaw in my solution.
Upvotes: -1
Views: 3008
Reputation: 15
Your second solution is correct, but because of the single space before ' Australia' in query (select continent from world where name IN ('Argentina',**' Australia'**) )
is giving you wrong output. You are not getting Continent name Oceania.
I hope this has given you clarity on the query.
select name,continent from world
where continent IN
(select continent from world where name IN ('Argentina','Australia'))
order by name
Upvotes: 0
Reputation: 1
This worked for me
select name,continent from world
where continent IN ( select continent
from world where name IN ('Argentina','Australia'))
ORDER BY name
Upvotes: 0
Reputation: 118
Becasue subquery in your first result will return multiple rows, and you can't use equal sign there so you have to check 'in' clause.
Upvotes: 1