skip to Main Content

Hi I have the following table,

FILE_NAME MODIFIED_DATE PRIORITY
A 2022-10-11 1
A 2022-10-03 1
A 2022-10-02 1
B 2022-10-11 3
B 2022-10-01 3
C 2022-10-11 2
D 2022-10-11 4

I would like to order the table based on MODIFIED_DATE, PRIORITY and FILE_NAME.

For example,

FILE_NAME MODIFIED_DATE PRIORITY
A 2022-10-11 1
C 2022-10-11 2
B 2022-10-11 3
D 2022-10-11 4
A 2022-10-03 1
A 2022-10-02 1
B 2022-10-01 3

What would be the most efficient way to do this?

2

Answers


  1. Most efficient seems to be the only reasonable one to me, i.e.

      SELECT FILE_NAME, MODIFIED_DATE, PRIORITY
        FROM ...
    ORDER BY MODIFIED_DATE, PRIORITY, FILE_NAME
    
    Login or Signup to reply.
  2. Looking at the sample data and expected output, It seems like you need ordering in following manner

    • MODIFIED_DATE DESC
    • PRIORITY ASC
    • FILE_NAME ASC (Not sure for FILE_NAME as not clear from your output)

    Best is to use ORDER BY clause with ASC(default)/DESC which is faster than any other method know to you (At least, I am not aware about any other method)

    So you can use

    ORDER BY MODIFIED_DATE DESC,
             PRIORITY,
             FILE_NAME
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search