Doubt related to alias

SELECT
department_name,
first_name,
last_name,
salary
FROM
(
SELECT
department_name,
ROW_NUMBER() OVER (
PARTITION BY department_name
ORDER BY salary DESC) row_num,
first_name,
last_name,
salary
FROM
employees e
INNER JOIN departments d
ON d.department_id = e.department_id
) t
WHERE
row_num = 1;

Here, what is the meaning of alias as it is running without alias as well…everywhere…as whether we write d.department_name or directly write department name it is not showing any error…what is the purpose of alias…also we are giving alias to table t but we directly access the row_num without using alias…??

But if not provide then definitely give error of not providing alias

Alias helps your code to become more readable by others as it clearly shows from where a given column comes up.
It helps while doing join as you can see we have two table and if we have to match the same column names from these two table then we need to use table_name.col_name syntax to uniquely identify the column.
Now in case of running subqueries in Postgresql you need to have the alias always otherwise it will give you error, that is part of the syntax of Postgresql (this might not be true for other DBs like Oracle).
Finally in the current query there is only 1 FROM table, so postgresql already understands that any column you reference will be coming from here, but think of the cases when you have multiple tables with same column names then in that case aliasing would be necessary.
In general when we have multiple table used in a query for better readability of code, we should alias the column names.

SIR actually in inner querry their are two tables and these two tables are having alias e and d respectively but while calling the department name the inner querry runs without using alias why that is so???

since the department_name is only in one of the table so Postgresql can handle this situation easily as it understands from where to get this column. (i.e. it is only in department table and not in employee table)
As i told you in the above reply as well postgresql is intelligent enough to find the columns even without alias in most of the cases but as a syntax rule you still require to put alias in the query to handle edge cases.

Ok…sir Thanks!