Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have a table (emp) with two columns in ORACLE:

COMPANY   OFFICE    EMP
------------------------
9999      00001     emp1
9999      00001     emp2
9999      00002     emp3
9999      00002     emp4
0001      99999     emp5
0001      00001     emp6
0001      00002     emp7
0002      00001     emp8
0002      99999     emp9
0003      99999     emp10
0003      00001     emp11
0003      00002     emp12

I want to get value in EMP column with following statement:

SELECT 
   EMP 
FROM 
   emp
ORDER BY COMPANY /*(But 9999 is first)*/, OFFICE /*(But 99999 is first).*/

I don't know how to do.

share|improve this question
    
I don't understand the output you want from your query. Can you write down the output you're expecting and then we can help you with your query. –  trygvis Nov 23 '12 at 23:51
    
Thanks dezso, my problem was solved, by Bary's way, thank you very much. –  TOMMY Dec 8 '12 at 16:23

2 Answers 2

I guess you want the results in ascending order but with 9999 always first?

Select EMP
From Emp
Order By Case When Company = 9999 Then -1 else Company End,
         Case When Office = 9999 Then -1 else Office End;
share|improve this answer
    
It helps me. Thank Barry very much! –  TOMMY Nov 23 '12 at 16:36

If I understand you correctly, you want to sort based on company in descending order, and then by office also in descending order

SELECT emp FROM emp ORDER BY company DESC, office DESC;
share|improve this answer
    
Thanks Roy for your answer. –  TOMMY Nov 23 '12 at 16:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.