Quote:
|
DISTINCT is ~not~ a function, DISTINCT applies to all columns in the SELECT clause
|
Yes! r937 was right.
Here are some other examples.
Example 1: make a subquery to correlated subquery(Add "WHERE am.column1 = a.column1")
Code:
SELECT a.column1
, a.column2
FROM siebel.table1 a
, siebel.table2 b
WHERE a.column3 = b.column3
AND a.column4
= (SELECT MAX(a.column4)
FROM siebel.table1 am
WHERE am.column1 = a.column1
)
;
Example 2: Move reference to table2 into EXISTS predicate.
Because, columns of table2 are not imcluded in final select-list.
Code:
SELECT a.column1
, a.column2
FROM siebel.table1 a
WHERE a.column4
= (SELECT max(a.column4)
FROM siebel.table1 am
WHERE am.column1 = a.column1
)
AND EXISTS(
SELECT 0
FROM siebel.table2 b
WHERE b.column3 = a.column3
)
;
Example 3: Make one reference to table1 by using ROW_NUMBER OLAP specification.
Code:
SELECT a.column1
, a.column2
FROM (SELECT a.*
, ROW_NUMBER()
OVER( PARTITION BY column1
ORDER BY column4 DESC
) rnum
FROM siebel.table1 a
WHERE EXISTS(
SELECT 0
FROM siebel.table2 b
WHERE b.column3 = a.column3
)
) a
WHERE rnum = 1
;