2016-03-01 175 views
-16

得我在我的表查詢相同的錯誤:SQL查詢返回錯誤結果

  1. 國家
  2. CountryLanguage

如果我把任何或所有關鍵字子查詢之前運行,但預計不會結果如何?

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

添加問題的有效標題。 –

+1

「abcdefghijklmnopqrstuvwxyz」 哈哈,認真嗎? – Chendur

+4

我不知道你在問什麼。 –

回答

0

由於子選擇可能返回多行,做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%'