How does order by clause works if two values are equal?

后端 未结 3 759
北荒
北荒 2021-01-11 10:44

This is my NEWSPAPER table.

    National News   A   1
    Sports          D   1
    Editorials      A   12
    Business        E   1
    Weather         C            


        
3条回答
  •  不知归路
    2021-01-11 11:07

    If you need reliable, reproducible ordering to occur when two values in your ORDER BY clause's first column are the same, you should always provide another, secondary column to also order on. While you might be able to assume that they will sort themselves based on order entered (almost always the case to my knowledge, but be aware that the SQL standard does not specify any form of default ordering) or index, you never should (unless it is specifically documented as such for the engine you are using--and even then I'd personally never rely on that).

    Your query, if you wanted alphabetical sorting by feature within each page, should be:

    select feature,section,page from NEWSPAPER
    where section = 'F'
    order by page, feature;

提交回复
热议问题