SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    absolute 1st or last order

    Code:
    data in myTable1
    
    (ID) name
    (1) Tom 
    (2) Jane 
    (3) Jack 
    (4) Mary 
    (5) Ted
    I have data in myTable1 like the above.
    Because (3) Jack is a kind of sticky, I like to make jack comes first or last.

    The following would-be code is one of my trials.
    But it seems to be not work as I want.
    Code:
    would be code
    
    select id, name, CASE WHEN id = '3' THEN 1 ELSE 2 END AS ORDER_KEY 
    from myTable1 
    order by ORDER_KEY, id 
     
    target result
    
    (3) Jack
    (1) Tom 
    (2) Jane  
    (4) Mary 
    (5) Ted

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dotJoon View Post
    But it seems to be not work as I want.
    Why? What happens? An error? Not the expected output (if so, what output do you get) ?


    And did you think about adding a 'sticky' column to your table?

  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Why? What happens? An error? Not the expected output (if so, what output do you get) ?
    Sorry, I made a mistake. Maybe it was Capital letters and Small letter problems.
    Now I got my target result.

    Thank you very much, guido2004.


Bookmarks

Posting Permissions

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