Why can identifiers in SQL be referenced before assignment?
It is alias for a table. But key point here is that SQL should not be read top-down.
SELECT A.id
FROM table_a A;
In reality is executed more like:
FROM table_a A
SELECT A.id;
Now it makes perfect sense.
Going further:
SELECT A.id + 1 AS c
FROM table_a A
WHERE c = 10;
-- error, we cannot use c, even if it was defined 2 lines before
Because the order is as follow:
FROM table_a A
WHERE c = 10 -- here C is not defined
SELECT A.id + 1 c;
Even on the same level in SELECT
it is also not possible to reuse defined alias:
SELECT a + 1 AS b, b + 1 AS c, c + 1 AS d
FROM tab
-- error
-- (some databases allow to use lateral column aliasing)
Related readings:
Why do “linq to sql” queries starts with the FROM keyword unlike regular SQL queries?
Lexical and logical SELECT clause order
All-at-once rule