MySQL Alias ​​Question

I wonder why this fails

mysql> SELECT Continent C, Name, SurfaceArea
    -> FROM Country
    -> WHERE SurfaceArea = (
    -> SELECT MAX (SurfaceArea)
    -> FROM Country
    -> WHERE Continent = C);
ERROR 1054 (42S22): Unknown column 'C' in 'where clause'

his response provided by certification guidance for some sample exercises.

btw, for an alias, when do I need to use AS? isit optional?

+3
source share
2 answers

To execute a correlated subquery, you need an alias for the external table . You have created an alias for an external field. , (Cou), ( , , . , )

SELECT Continent, Name, SurfaceArea
FROM Country Cou
WHERE SurfaceArea = 
(
    SELECT MAX(SurfaceArea)
    FROM Country
    WHERE Continent = Cou.Continent
);

AS . , Country AS Cou, .

+8

, - , MySQL. , ( , ). MySQL 5.0.45.

MySQL , . , / ( , / PDF , , ).

, , AS .

0

Source: https://habr.com/ru/post/1717312/


All Articles