Order by with WITH clause [message #633851] |
Thu, 26 February 2015 04:38 |
|
sss111ind
Messages: 634 Registered: April 2012 Location: India
|
Senior Member |
|
|
Hi All,
The 1st code is working fine but 2nd code is not working .
WITH temp AS (SELECT * FROM emp)
SELECT * FROM (SELECT temp.*,row_number() OVER(PARTITION BY JOB ORDER BY JOB,hiredate) rn FROM temp)
WHERE rn=1
UNION ALL
SELECT temp.*,1 FROM temp ORDER BY 3,5;
WITH temp AS (SELECT * FROM emp)
SELECT * FROM (SELECT temp.*,row_number() OVER(PARTITION BY JOB ORDER BY JOB,hiredate) rn FROM temp)
WHERE rn=1
UNION ALL
select temp.*,1 from temp order by JOB,HIREDATE;
Regards,
Nathan
|
|
|
|
Re: Order by with WITH clause [message #633855 is a reply to message #633851] |
Thu, 26 February 2015 05:10 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Or, project the columns explicitly:
orclz> select * from dept union select * from dept order by dname;
select * from dept union select * from dept order by dname
*
ERROR at line 1:
ORA-00904: "DNAME": invalid identifier
orclz> select deptno,dname,loc from dept union select deptno,dname,loc from dept order by dname;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
40 OPERATIONS BOSTON
20 RESEARCH DALLAS
30 SALES CHICAGO
orclz>
|
|
|
|