You cannot reference the alias that you created in SELECT , use the expression instead:
SELECT CONCAT( t.str1, t.str2 ) AS Title, CHAR_LENGTH(CONCAT( t.str1, t.str2 ) ) AS Length FROM table_name t
You can use a subquery if you need:
SELECT sub.Title, CHAR_LENGTH( sub.Title ) AS Length FROM ( SELECT CONCAT( t.str1, t.str2 ) AS Title FROM table_name t ) AS sub;
All-at-once operation :
"All-at-Once operations" means that all expressions in the same logical logical sequence of queries are logically evaluated at the same time.
and
We cannot use an alias in the following column expression in a SELECT clause. In the request, we create the corrected first name, and we want to use it in the next column to get the full name, but the βAll at onceβ operation concept tells us that you cannot do this because all the expressions in the same phase are executed a logical query process (here SELECT) logically at the same time.
source share