|
Tutorial OneNotes 3 |
Using nested select statements
The result of a SELECT statement may be used as a value in another statement. For example the statement SELECT region FROM cia WHERE name = 'Brazil' evaluates to 'South America' so we can use this value to obtain a list of all countries in the same region as 'Brazil'
SELECT name FROM cia WHERE region = (SELECT region FROM cia WHERE name = 'Brazil')
Note that this is not the same thing as a join.
Observe the tables which result from each of the following
SELECT name FROM cia WHERE region = (SELECT region FROM cia WHERE name = 'Belarus')
| name |
|---|
| Armenia |
| Azerbaijan |
| Belarus |
| Moldova |
| Ukraine |