Certain predicates can contain subqueries. These subqueries, in turn, can contain other subqueries, etc. A
subquery with further subqueries is the higher-level subquery of the subqueries it contains.If the qualifying table name or reference name does not clearly identify a table at a higher level, the table at the lowest level is taken from these non-unique tables.
If the column name is not qualified by the table name or reference name, the tables at higher levels are searched. The column name must be unique in all tables of the from clause to which the table found belongs.
If a correlated subquery is used, the values of one or more columns in a temporary result row at a higher level are included in the search condition of a subquery at a lower level, whereby the result of the subquery is used to uniquely qualify the higher-level temporary result row.
Model tables
SELECT name, city FROM hotel X, room
WHERE X.hno = room.hno AND room.price <
(SELECT AVG(room.price) FROM hotel, room
WHERE hotel.hno = room.hno AND hotel.city = X.city )