嵌套SELECT語句也叫子查詢,形如:
SELECT name FROM bbc WHERE region = (SELECT region FROM bbc WHERE name = 'Brazil')一個 SELECT 語句的查詢結果可以作為另一個語句的輸入值。上面的SQL語句作用為獲得和'Brazil'(巴西)同屬一個地區的所有國家。
SELECT name FROM bbc WHERE region IN (SELECT region FROM bbc WHERE name = 'Brazil')OK,
一、給出人口多於Russia(俄國)的國家名稱 SELECT name FROM bbc WHERE population> (SELECT population FROM bbc WHERE name='Russia')
二、給出'India'(印度), 'Iran'(伊朗)所在地區的所有國家的所有信息 SELECT * FROM bbc WHERE region IN (SELECT region FROM bbc WHERE name IN ('India','Iran'))
三、給出人均GDP超過'United Kingdom'(英國)的歐洲國家. SELECT name FROM bbc WHERE region='Europe' AND gdp/population > (SELECT gdp/population FROM bbc WHERE name='United Kingdom')