Results 1 to 2 of 2
  1. #1
    Join Date
    May 2003
    Posts
    4

    Unanswered: Question on SQL Server2000's order by clause

    Hi,
    I have problem of order by clase.
    Must I specify the column in both select clause and order by clause
    so as to get the correct result?

    If I omit the order by column in select clause(for example:
    select order.*, cl.ID from T_ORDER order, T_CLIENT cl where .... order by cl.code),
    would MS SQL server 2000 still correctly or ignore order by clause completely?


    It seems the latter actually happens.

    BTW, how would other DBMS handle this case?

    Regards,
    Justin

  2. #2
    Join Date
    Feb 2004
    Location
    San Antonio, TX
    Posts
    565
    in SQL the ORDER BY clause is independent of the actual query is so far as you can sort by a column that is not listed in the select list

    for example

    select fname , lastname, middle
    from t1
    order by zipcode

    on a side note you can also order by the ordinal number of the columns in the result set but this is confusing and not good form

    ex
    select fname , lastname, middle
    from t1
    order by 2

    does this answer your question?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •