Order By Column

  • Anoo S Pillai

    Mr or Mrs. 500

    Points: 547

    Comments posted to this topic are about the item Order By Column

  • Ford Fairlane

    SSCertifiable

    Points: 7664

    Option 3

    Hope this helps...

    Ford Fairlane
    Rock and Roll Detective

  • Koen Verbeeck

    SSC Guru

    Points: 258965

    Nice question, but the explanation doesn't mention why the order of casting vs order by changes. (because of adding the T alias in the second statement)

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • This was removed by the editor as SPAM

  • Hany Helmy

    SSChampion

    Points: 13488

    Koen Verbeeck (3/4/2014)


    Nice question, but the explanation doesn't mention why the order of casting vs order by changes. (because of adding the T alias in the second statement)

    + 1

  • Hany Helmy

    SSChampion

    Points: 13488

    Interesting QotD.

  • free_mascot

    One Orange Chip

    Points: 27168

    Good one! thanks.

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

  • paul s-306273

    SSChampion

    Points: 10615

    Nice qotd.

  • andrew.manning

    Mr or Mrs. 500

    Points: 588

    Interesting, I never realised that you could order by a column alias.

    I have to admit that I assumed that the same principle of not being able to use column aliases in WHERE, HAVING, GROUP BY, etc. clauses would apply.

    Nice to know that's not the case though.

  • twin.devil

    SSC-Insane

    Points: 22208

    nice question .... but Who Cares 😛

  • Anoo S Pillai

    Mr or Mrs. 500

    Points: 547

    twin.devil (3/4/2014)


    nice question .... but Who Cares 😛

    Still remember the pale face of a report developer who wants his data sorder in descending date order, but it was showing in descending string order. 😉

    Nice to see that the third option is a valid answer:hehe:

  • Ed Wagner

    SSC Guru

    Points: 286985

    +1. However, it was an interesting one. Thanks for the question.

  • sestell1

    SSChampion

    Points: 10230

    Argh, you got me. Good question!

    Yet another reason to add to my list for always prefixing table names or aliases.

  • SQLRNNR

    SSC Guru

    Points: 281252

    Koen Verbeeck (3/4/2014)


    Nice question, but the explanation doesn't mention why the order of casting vs order by changes. (because of adding the T alias in the second statement)

    That explanation is important for this question and would have made the question better.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • RLilj33

    SSCrazy

    Points: 2153

    Koen Verbeeck (3/4/2014)


    Nice question, but the explanation doesn't mention why the order of casting vs order by changes. (because of adding the T alias in the second statement)

    I remember being confused by this many years ago (won't say how many :-D) when I first encountered it. Hopefully this post will help alleviate some frustration.

    When the table alias is included in the ORDER BY clause, the table field value is used to order the records. When it is not, the alias (i.e. the calculated value) is used to order the records.

Viewing 15 posts - 1 through 15 (of 37 total)

You must be logged in to reply to this topic. Login to reply