Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Order by clause

user10926431Aug 18 2010 — edited Sep 4 2010
I have table emp

empno ename sal
101 suresh 1250
105 chowdary 850
103 gottipati 1700
102 abcd 720



I want to display data(empno,sal columns assceeding order)

empno sal
101 720
102 850
103 1250
105 1700
This post has been answered by 678284 on Aug 18 2010
Jump to Answer

Comments

baskar.l
hi,
SQL> select * from testing;

     EMPNO ENAME                       SAL
---------- -------------------- ----------
         2 bas                        2000
         1 sun                        3000
         3 ben                        4000

3 rows selected.

SQL> select * from testing order by empno;

     EMPNO ENAME                       SAL
---------- -------------------- ----------
         1 sun                        3000
         2 bas                        2000
         3 ben                        4000

3 rows selected.
thanks,
baskar.l
user10926431
I want to display data both columns are acceding order.....(both columns are not dependent)
678284
Answer
order by empno,sal;
Marked as Answer by user10926431 · Sep 27 2020
user10926431
Both columns are not dependent.........,

i want to display each columns are individually.......
678284
user10926431 wrote:
Both columns are not dependent.........,

i want to display each columns are individually.......
I see.
select
nth_value(empno,rownum) over(order by empno rows between unbounded preceding and unbounded following),
nth_value(sal,  rownum) over(order by sal   rows between unbounded preceding and unbounded following)
from emp;
user10926431
i tried , but it's getting error
678284
what's oracle version?
user10926431
10.2.0.3.0
678284
user10926431 wrote:
10.2.0.3.0
I am FOND of nth_value,in fact.
10.2.0.3.0 doesn't have nth_value.

Let's use row_number then inner join each other
787049
I think this would be helpful.
SELECT A.empno, B.sal 
FROM 
(SELECT rownum r1, empno from (SELECT empno FROM emp ORDER BY empno)) A, 
(SELECT rownum r2, sal FROM (SELECT sal FROM emp ORDER BY sal)) B 
WHERE A.r1 = B.r2
Edited by: Zeynal Zeynalov on Aug 18, 2010 4:13 AM
MichaelS
10.2.0.3.0 doesn't have nth_value.
even if it had it wouldn't work that way:
SQL> select rownum,
            nth_value(empno,rownum) over(order by empno rows between unbounded preceding and unbounded following) empno,
            nth_value(sal,  rownum) over(order by sal   rows between unbounded preceding and unbounded following) sal
from emp order by rownum
/
    ROWNUM      EMPNO        SAL
---------- ---------- ----------
         1       7369        800
         2       7369        800
         3       7369        800
         4       7369        800
         5       7369        800
         6       7369        800
         7       7369        800
         8       7369        800
         9       7369        800
        10       7369        800
        11       7369        800
        12       7369        800
        13       7369        800
        14       7369        800

14 rows selected.
Aketi Jyuuzou
even if it had it wouldn't work that way:
I suppose that is bug.
I have made thread.
1118408
OraLearner
http://oraclelabs.com/index.php/2010/09/03/useful-tips-of-order-by-clause/

Regards
1 - 13
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Oct 2 2010
Added on Aug 18 2010
13 comments
1,825 views