SQL查询返回错误的结果

时间:2016-03-01 09:57:41

标签: sql oracle

在我的桌子上查询时遇到同样的错误:

  1. 国家
  2. CountryLanguage
  3. 如果我在子查询之前放置任何或所有关键字,它会运行但不是预期结果?

    select countrycode,language
    from countrylanguage 
    where countrycode =
    (select countrycode from country where region like '%Asia%');
    

1 个答案:

答案 0 :(得分:1)

由于子选择可能会返回多行,请执行IN而不是=

select countrycode, language
from countrylanguage 
where countrycode IN (select countrycode from country where region like '%Asia%');

或者,或许更好,改为JOIN

select countrycode, language
from countrylanguage  cl
join country c ON cl.countrycode = c.countrycode 
where c.region like '%Asia%'
相关问题