Results 1 to 3 of 3

Thread: Order By

  1. #1
    Join Date
    May 2004
    Posts
    36

    Unanswered: Order By

    i want to use an order by clause. my issue is that the values i have are alpha and i need the top of the order to be 'A', 'S', then what ever. how can i sort this column and have the top two being 'A's and 'S's????


    thanks in advance
    e

  2. #2
    Join Date
    Jul 2004
    Posts
    13
    There are several ways. Perhaps the laziest is to select a field only for ordering purposes.

    SELECT lastname, toto, tata
    CASE WHEN lastname LIKE ('A%') THEN 1
    WHEN lastname LIKE('S%') THEN 2
    ELSE 3
    END as Ord
    ORDER by ord, lastname

    Another is to use several queries and the UNION operator

    SELECT .. FROM ..
    WHERE
    lastname like ('A%')
    ORDER BY lastname
    UNION
    ...
    where lastname like ('S%')
    ORDER BY lastname

    UNION
    WHER lastname not like ('A%') and lastname not like ('S%')
    ORDER BY lastname

  3. #3
    Join Date
    May 2004
    Posts
    36
    i think i can make that work... thanks

Posting Permissions

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