I've found a very strange behavior in UNIONed select
statements with same values.
tried to find something on the web for whats happening, but didn't know how to phrase the search for this issue, it needs explanation, and it is as follows:
Test 1:
SELECT
ID, SUM(AMT) AS AMT
FROM
(
SELECT 1 AS ID, 100 AS AMT FROM DUAL UNION
SELECT 1 AS ID, 100 AS AMT FROM DUAL UNION
SELECT 1 AS ID, 100 AS AMT FROM DUAL UNION
SELECT 1 AS ID, 100 AS AMT FROM DUAL
)
GROUP BY ID;
Test 2:
SELECT 1 AS ID, 100 AS AMT FROM DUAL UNION
SELECT 1 AS ID, 100 AS AMT FROM DUAL UNION
SELECT 1 AS ID, 100 AS AMT FROM DUAL UNION
SELECT 1 AS ID, 100 AS AMT FROM DUAL;
All these select statements are giving the same result:
So, supposing I'm writing a dynamic code to be generated and executed at run time in one of my apps, and it happens that the code turned up to be as above! how to make this select statement work ?