• raulggonzalez (7/15/2013)


    It's funny, though, that if you alias the column, both names can be used (original & alias) in the ORDER BY clause

    Try to think of the column alias as a very simple expression

    So Col1 AS X = 1 * Col1 AS X

    In queries you can sort by expressions AND by the original table columns, even if they are not included in the output. If I include the original column in the output, it should become more clear:

    SELECT a AS x -- "Computed" column

    ,a -- "Original" column

    FROM(SELECT 1 AS a) d

    ORDER BY

    x

    ,a

    [Edit: Added query comments]

    Best Regards,

    Chris Büttner