Group By clause in inline view [message #650173] |
Mon, 18 April 2016 10:05 |
lancer26
Messages: 52 Registered: May 2006 Location: Pakistan
|
Member |
|
|
Dear Gurus,
Please check below query and explain why it's working, as my understanding, it should not work, because of inline view, ID column is not part of Group by clause.
if i run only inner query, it gives me error "not a group by expression", but when we use it as inline view and then select aggregate then it'll work.
Query is below
WITH CTE
AS
(
SELECT 1 ID, 'A' D FROM DUAL
UNION
SELECT 2 ID, 'B' FROM DUAL
UNION
SELECT 3 ID, 'C' FROM DUAL
)
SELECT MAX_ID
FROM (
SELECT ID, MAX(ID) MAX_ID
FROM CTE
GROUP BY D
)
;
|
|
|
|
|
|
|
|
|