Quick
Ref.
| Using SELECT in SELECT See SELECT FROM SELECT for how to use a derived table. The result of a SELECT statement may be used as a value in
another statement. For example the statement
SELECT region FROM bbc WHERE name = 'Brazil'
evaluates to
NotesSome versions of SQL insist that you give the subquery an alias. Simply put SELECT name FROM bbc WHERE region = (SELECT region FROM bbc WHERE name='Brazil') AS brazil_region Multiple results from the subqueryThe subquery may return more than one result - if this happens the query will fail as you are testing one value against more than one value. It is safer to use IN to cope with this possibility The phrase SELECT name, region FROM bbc
WHERE region IN (SELECT region FROM bbc WHERE name='Brazil'
OR name='Mexico')
|