Results 1 to 2 of 2

Thread: Sql Query - ORDER BY - help please?

  1. #1
    Col Guest

    Sql Query - ORDER BY - help please?


    Hi Guys

    I was wondering whether it is possible to do the following in an SQL query.
    I do not want to break the query out into a Stored Procedure or Add a new field to my dB for the "Order By".

    Say I have 5 results:

    1. Opel
    2. Ford
    3. Toyota
    4. Audi
    5. Volkswagen

    I would like to ORDER them by NAME ASC but want Volkswagen to be the first record and then rest to be in Alphabetical.
    eg.

    5. Volkswagen
    4. Audi
    2. Ford
    1. Opel
    3. Toyota

    Is this possible in a "select NAME from TABLE order by NAME" query?

    Thanks for your help.
    Regards
    Col





  2. #2
    Col Guest

    Sql Query - ORDER BY - help please? (reply)


    If anyone is interested, this is how I ended up getting it done:


    select case when carname='Volkswagen' then 1 else 2 end as rectype , carname
    from cartable
    order by rectype, carname



    ------------
    Col at 8/30/2002 11:40:55 AM


    Hi Guys

    I was wondering whether it is possible to do the following in an SQL query.
    I do not want to break the query out into a Stored Procedure or Add a new field to my dB for the "Order By".

    Say I have 5 results:

    1. Opel
    2. Ford
    3. Toyota
    4. Audi
    5. Volkswagen

    I would like to ORDER them by NAME ASC but want Volkswagen to be the first record and then rest to be in Alphabetical.
    eg.

    5. Volkswagen
    4. Audi
    2. Ford
    1. Opel
    3. Toyota

    Is this possible in a "select NAME from TABLE order by NAME" query?

    Thanks for your help.
    Regards
    Col





Posting Permissions

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