query output doubt
Hi Team,
My Oracle version is 12c. I am executing below query.
query:
select id,TO_CHAR(end_date,'MM/DD/YYYY') AS end_date
from fund_id where id in
(2375340, 2374915, 2373796, 2373276, 2377976)
ORDER BY end_date DESC;
output:
ID | END_DATE |
---|---|
2375340 | 12/27/2024 |
2374915 | 12/26/2024 |
2373796 | 12/23/2024 |
2373276 | 12/20/2024 |
2377976 | 1/6/2025 |
Above output is incorrect as top end_date should be 01 jan 2025.
whereas if i am executing query using alias(as mentioned below). then its giving correct output as below:
query:
select id,TO_CHAR(end_date,'MM/DD/YYYY') AS end_date
from fund_id a where id in
(2375340, 2374915, 2373796, 2373276, 2377976)
ORDER BY a.end_date DESC;
output:
ID | END_DATE |
---|---|
2377976 | 1/6/2025 |
2375340 | 12/27/2024 |
2374915 | 12/26/2024 |
2373796 | 12/23/2024 |
2373276 | 12/20/2024 |
My question is why output is impacted if anything change in select query columns(to_char function applied in column end_date ) and allias not used. I think ideally select query column should not impact the order by clause output. Could anyone tell me if oracle is behaving correctly in this case.