I was just wondering, why does:
select max(run_id) as run_id from my_table where run_id > 50;
It gives an error and
select max(run_id) as max_run_id from my_table where run_id > 50;
select max(run_id) from my_table where run_id > 50;
the above two queries does not give an error.
Let's say the structure of the table is,
create table my_table(
run_id int,
something varchar(10))
This table has 100 run_id's.
I know you can't use where clause with aggregate functions.
Is it because we rename the column (as max_run_id) and the sql is treating it as a separate column, where if the name was the same as the original column it sees the aggregate function and gives the error because of it? Or can someone explain that with better terms.