SQL Reverse "Order By"

Ok I'm trying to order by a column which consists of numbers,
which works, however, I want the high numbers at the top not the
bottom. Now I know DESC works for alphabetical entries, but what
works for numbers? This has to be simple. Thanks!

ORDER BY therank, votes DESC will order by therank ascending
first, then by votes descending. So, if you have more than one row
with the same value for therank, then those rows will be ordered in
descending order by the value of votes. If you want it by votes
descending first, then ORDER BY votes DESC, therank.
One question: What is the actual datatype of the votes
column? If it is actually varchar/text, even though it contains
numbers, then you may have a "weird" or unexpected sort order
because it is going to sort "numbers" like 1, 10, and 100 in by
their "text" order, not their numeric. You can correct for that by
doing something like CASTing the column to numeric in the ORDER BY
clause, provided of course that ALL of the values in the column are
numbers.
Phil

Similar Messages

  • Why do RefCursors return result sets in reverse order?

    Oracle XE version 10.2.0.1 (both windows and Linux perform the same).
    I'm porting code from DB2 to Oracle - our environment is mostly stored procedures returning REFCURSORS to a java layer. Many of the stored procedures return more than one REFCURSOR (please no posts on the value of packages vs procs, I understand the benefit but cannot switch at this time to packages). It took me a while to figure this out, but it appears that the cursors are returned in reverse order of their OUT param position(s). My fear is that this isn't always the case, but that the cursors could be open in some random order, in which case any conditional processing I have would need to account for that. Anyone experience this? Or can any Oracle guru explain why the cursors are open in reverse order? At this point in time, I do need to process them positionally rather than naming them -
    Here's a test case:
    CREATE TABLE TESTCUR(
    col1 NUMBER,
    col2 VARCHAR2(50)
    INSERT INTO TESTCUR VALUES (1, 'value for cursor 1');
    INSERT INTO TESTCUR VALUES (2, 'value for cursor 2');
    INSERT INTO TESTCUR VALUES (3, 'value for cursor 3');
    CREATE OR REPLACE PROCEDURE TESTREFCURSORMULTI (
      testcasenumber IN NUMBER,
      cv_1 OUT SYS_REFCURSOR,
      cv_2 OUT SYS_REFCURSOR,
      cv_3 OUT SYS_REFCURSOR
    AS
    BEGIN
         IF testcasenumber = 1 THEN
         OPEN cv_1 FOR
              SELECT col2
              FROM TESTCUR
              WHERE col1 = 1;
         OPEN cv_2 FOR
              SELECT * FROM DUAL WHERE 1=0;
         OPEN cv_3 FOR
              SELECT * FROM DUAL WHERE 1=0;
         ELSE
              IF testcasenumber = 2 THEN
              OPEN cv_1 FOR
                   SELECT col2
                   FROM TESTCUR
                   WHERE col1 = 2;
              OPEN cv_2 FOR
                   SELECT * FROM DUAL WHERE 1=0;
              OPEN cv_3 FOR
                   SELECT * FROM DUAL WHERE 1=0;
              ELSE
                   OPEN cv_1 FOR
                        SELECT col2
                        FROM TESTCUR
                        WHERE col1 = 1;
                   OPEN cv_2 FOR
                        SELECT col2
                        FROM TESTCUR
                        WHERE col1 = 2;
                   OPEN cv_3 FOR
                        SELECT col2
                        FROM TESTCUR
                        WHERE col1 = 3;
              END IF;
         END IF;
    END;
    set autoprint on
    var rc1 refcursor
    var rc2 refcursor
    var rc3 refcursor
    begin
    TESTREFCURSORMULTI(
    testcasenumber => 3,
    cv_1 => :rc1,
    cv_2 => :rc2,
    cv_3 => :rc3)
    end;
    /     Here are the results when opening all three:
    SQL> begin
      2  TESTREFCURSORMULTI(
      3  testcasenumber => 3,
      4  cv_1 => :rc1,
      5  cv_2 => :rc2,
      6  cv_3 => :rc3)
      7  ;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    COL2
    value for cursor 3
    COL2
    value for cursor 2
    COL2
    value for cursor 1Results when opening 1:
    SQL> set autoprint on
    SQL> var rc1 refcursor
    SQL> var rc2 refcursor
    SQL> var rc3 refcursor
    SQL> begin
      2  TESTREFCURSORMULTI(
      3  testcasenumber => 1,
      4  cv_1 => :rc1,
      5  cv_2 => :rc2,
      6  cv_3 => :rc3)
      7  ;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    no rows selected
    no rows selected
    COL2
    value for cursor 1

    It nothing more but the way how AUTOPRINT works:
    SQL>  set autoprint on
    SQL> var rc1 refcursor
    SQL> var rc2 refcursor
    SQL> var rc3 refcursor
    SQL> begin
      2  TESTREFCURSORMULTI(
      3  testcasenumber => 3,
      4  cv_1 => :rc1,
      5  cv_2 => :rc2,
      6  cv_3 => :rc3)
      7  ;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    COL2
    value for cursor 3
    COL2
    value for cursor 2
    COL2
    value for cursor 1
    SQL> set autoprint off
    SQL> begin
      2  TESTREFCURSORMULTI(
      3  testcasenumber => 3,
      4  cv_1 => :rc1,
      5  cv_2 => :rc2,
      6  cv_3 => :rc3)
      7  ;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> print rc1
    COL2
    value for cursor 1
    SQL> print rc2
    COL2
    value for cursor 2
    SQL> print rc3
    COL2
    value for cursor 3
    SQL> As you can see, right cursor returned right result, just autoprint in case of multiple variables prints results starting last open cursor:
    SQL> set autoprint on
    SQL> begin
      2  open :rc1 for 'select 1 from dual';
      3  open :rc2 for 'select 2 from dual';
      4  open :rc3 for 'select 3 from dual';
      5  end;
      6  /
    PL/SQL procedure successfully completed.
             3
             3
             2
             2
             1
             1
    SQL> begin
      2  open :rc3 for 'select 3 from dual';
      3  open :rc2 for 'select 2 from dual';
      4  open :rc1 for 'select 1 from dual';
      5  end;
      6  /
    PL/SQL procedure successfully completed.
             1
             1
             2
             2
             3
             3
    SQL> SY.

  • Connect by prior - reverse order

    Is this possible:
    emp - manager
    a 0
    b a
    c a
    d b
    I can start with the manager = 0 and get the entire tree. I want to start with emp = c and get the tree going the other way .. reverse order. Is this possible ?

    Do you mean:
    SQL> SELECT * FROM t[
    EMP        MGR
    a          0
    b          a
    c          a
    d          b
    SQL> SELECT LPAD(' ',2*(LEVEL-1))||emp emp, mgr
      2  FROM t
      3  START WITH emp = 'c'
      4  CONNECT BY PRIOR mgr = emp;
    EMP        MGR
    c          a
      a        0TTFN
    John

  • How to display text in reverse order ?

    I was wondering how to display data [text-numbers...etc] in the reversed order.
    E.g.
    if the data is as follows:
    ORACLE
    it should be displayed as:
    ELCARO
    thanx in advance !

    An alternative would be a MODEL clause solution:Nice!
    Here another alternative with only one measure:
    SQL> create table t
      2  as
      3  select 'bocajijA' col1 from dual union all
      4  select 'ORACLE' from dual union all
      5  select null from dual
      6  /
    Tabel is aangemaakt.
    SQL> select old_col
      2       , col1
      3    from t
      4   model
      5         partition by (col1 old_col)
      6         dimension by (0 i)
      7         measures (col1)
      8         rules iterate(10000) until (iteration_number = length(col1[0])-1)
      9         ( col1[0]
    10           = substr(col1[0],1,iteration_number) ||
    11             substr(col1[0],length(col1[0]),1) ||
    12             substr(col1[0],iteration_number + 1, length(col1[0])-iteration_number-1)
    13         )
    14  /
    OLD_COL  COL1
    bocajijA Ajijacob
    ORACLE   ELCARO
    3 rijen zijn geselecteerd.Regards,
    Rob.

  • Scanned items show up in REVERSE order

    HP, please be more desriptive. I read previous posts and still cannot fix.
    When I scan a 5 page document, 1-5, it shows up on my MAC 10.9 in the order 5-1.
    One of your posts says in the "Copy" settings on the printer to change to "Collate On", then save default.
    I did this and it still shows up in the wrong order.
    I scan large documents everyday and need to have in correct order.
    Please help and be very specific!!!!
    Thank you,
    Terry

    Hello tryii223,
    Welcome to the HP Forums!
    I understand when you scan a document, then scans are showing in reverse order. Just to clarify this issue, I need to ask you some question:
    I need to find out what type of printer do you have? Click here to find out: Model Number.
    How is this printer connected? Wireless or USB?
    Are you using the scanner glass or automatic document feeder? If you're using the automatic document feeder, are you placing these pages 1-5 or 5-1?
    Please verify this information and I will assist you further. Have a great night!
    I worked on behalf of HP.

  • How do I get my ipod to play a playlist from reverse order? (Start with recently added song instead of first added)

    How do I get my ipod to play a playlist from reverse order? (Start with recently added song instead of first added)
    So I'm adding new songs to a very old playlist? Is there anyway that when I add them, they automatically go to top of playlist? How about getting one song to the top of a playlist.  That drag to arrange function is very annoying because it is slow and the playlist does not scroll up very well on a PC.

    Make a new playlist by pressing the little plus button at the very lower left corner of iTunes. An new playlist will appear in the Source pane called "untitled playlist". While the name is highlighted, you can change it to whatever you want. Drag all of the tracks from all the albums that comprise a single book to that playlist. Sync that playlist to your iPod.

  • Reverse order in File- Open dialogue

    The file/folder list in the File->Open dialogue window is "stuck" at showing in reverse order. I can right-click in the Open dialogue window and sort ascending, but the next time I open a file it is back to reverse order.
    I have experimented with Explorer's view settings but Reader appears to ignore those. Other applications, for example Word, use Explorer's view settings and behave as I would expect.
    I suspect that someone has inadvertently changed something on this PC. Perhaps there's a keystroke combination that changes the file display order persistently?
    Any ideas, please?
    Adobe Reader version 8.1.2
    XP Pro SP2

    I'm still struggling with this - does anyone know how to change the file sort order in the File->Open dialogue?
    It must be possible to change it because it has somehow been changed to reverse order!

  • Songs are in reverse order on iPad, but correct on iTunes

    I have a number of Smart Playlists that look fine when displayed on iTunes, but when iTunes copies them to my iPad Air, the list of albums shows up in the correct order but the songs in each album are sorted in reverse order.
    So for example, I have a Smart Playlist defined where "Artist is Jean Michel Jarre".  That playlist is sorted by Year in list view and by Year-then-Title in Grid view.
    When I look at that same Playlist on my iPad Air, all of his albums appear in chronological order (which I expect), but the songs on each album are listed last-to-first.  So Oxygene (his first album) shows up before Equinoxe (his second album), but the list of songs on the Oxygene album are shown as: Part VI, Part V, Part IV, Part III, Part II, Part I.  All of the albums on the list are in the right order, but the list of songs on each album appears backwards in each one.
    This is just one example of a bug that manifests itself a lot on my iPad.  I have a lot of Smart Playlists that misbehave just like this.  I deal with it by creating not-smart playlists that are exact copies of the Smart Playlists -- but honestly, why offer Smart Playlists if they're not going to display correctly?  If they're this buggy, why am I using them at all?
    Does anybody know of a workaround for this bug?  Does anybody know whether Apple is aware of it, and if they have any plans to fix it?  Please? Maybe? Someday?

    I am now home from work, and over the past hour I have tried every combination of up-arrows, down-arrows, Copy To Play Order, sorting on the leftmost column, sorting on the Year column, etc. etc. that I could think of.  I believe I have followed your recommendations slavishly and to the letter.
    My Jean Michel Jarre Smart Playlist is sorted with the triangle on the leftmost column, and in iTunes, the playlist order is correct.  I have sync'd my iTunes library to the iPad several times, I have unchecked that playlist, performed the sync again to remove it from the iPad entirely, checked it again and performed the sync again -- I have also tried closing the Music app on the iPad and restarting it -- I've also tried deliberately sorting the tracks in iTunes in reverse order to see if the iPad does anything any differently, including a "Copy to Play Order" for good luck -- and every combination of all of these choices results in exactly the same outcome: on the iPad, albums show up in chronological order, and tracks in each album show up in reverse order.  Nothing I do makes any difference at all.
    Here's hoping iOS 8 at least doesn't make things any worse.  Maybe if the gods are smiling, it might actually solve this problem.  I was hoping that the upgrade to iTunes 11.4 might have made a difference, but, sadly, no such luck ... which is why my hopes for salvation in iOS 8 are not high ... but that doesn't stop me from being grateful to you for trying to help.  Thank you for your time.  I do appreciate it.

  • How to print a document in reverse order using Java Print API ?

    I need to print a document in reverse order using Java Print API (*Reverse Order Printing*)
    Does Java Print API supports reverse order printing ?
    Thnks.,

    deepak_c3 wrote:
    Thanks for the info.,
    where should the page number n-1-i be returned ?
    Which method implementation of Pageable interface should return the page number ?w.r.t. your first question: don't return that number but return page n-1-i when page i is requested; your document will be printed in reverse order. Your class should implement the entire interface and wrap the original Pageable. (for that number n your class can consult the wrapped interface; read the API for the Pageable interface).
    kind regards,
    Jos

  • Just purchased a new iMac and transferred all info from my old iMac. Now when using iPhoto slideshow is displays the pictures in reverse order.

    Just purchased a new iMac and after transferring all info from my old iMac.  Now when using iPhoto slideshow it  displays the pictures in reverse order.

    There's a bug in iPhoto 9.5.1 and Mavericks that affects slideshows played directly from an album.  The slideshow will not play correctly if the photos have been sorted manually.  Any other type of sort, date, rating, keyword or title, will play correctly.
    If you need that manual sort of pictures for your slideshow create the slideshow in iPhoto's slideshow mode.
    OT

  • Urgent: How to bring the same pricing procedure in reversal order??

    Hi,
    We have recently implementated CIN at our client location. For the orders present in the system before CIN implementation, when we are creating the reversal orders, system is bringing the new pricing procedure with CIN condition types?
    Can we bring the same pricing procedure in the reversal order as in the sales order? 
    Please advise urgently.
    Regards,
    Peeyoosh.

    Dear Peeyoosh
    I am unable to understand from your comments
    "For the orders present in the system before CIN implementation, when we are creating the reversal orders"
    Please let me know how do you reverse a sale order.  To my knowledge, we can reverse delivery and billing but not sale order.  Either we can close the sale order by assigning some reason for rejection or delete the sale order.
    This being the case, please let me know why you are reversing and how you are reversing.  If you want the same pricing procedure for both normal sales and returns, then maintain the same pricing procedure for both document types.
    thanks
    G.  Lakshmipathi

  • How to copy images from another MC in reversed order??

    Hi everyone,
    I'm new to AS3 and have been fighting and searching for a solution to this problem for a week now, and I'm VERY close!
    I crated a MC holding of a series of images (about 50) and I jump around in it using plenty AS3 scripts (most of which I don't fully understand yet, but I'm working on that to! )
    I had to find a way to "rewind" (= play backwards) the MC. Since there is a stop(); command in almost every frame, prevFrame does not work and if I put that in a loop, it goes WAY to fast (but worked).. So I could think of only one way...
    Create a new (reverserd) MC with the same image sequence ald reverse it manually and play that one.
    This all works fine (very proud of it ).
    Now my question:
    To get this to work for multiple image sequences, I have to load all images twice (once in MC_1 and again in MC_2 and select them and reverse them).
    Not a big one, unless you want to create MANY of those SWF's...
    Is it possible to load the 50 images of the first MC in reverse into the second MC dynamically? JUST the images, noting else.
    extra info: the MC_2 is already in the lib(empty) and placed on the stage.
    something like:
    var pointer:Number=1;
    for (var:i:Number=50;i>=0;i--) {
    get MC_1.picure(var);
    put it in MC_2.frame(pointer);
    pointer = pointer + 1;
    All help is welcome and please take into account that I have little experience and copy most of my scripting from people like you
    T.I.A.
    Melluw

    I tried your advice (thanks for that)
    The event I already have is the mouse leave
    I //-d out the part I removed (what did work)
    The code I ended up with is:
    function Start() {
    stage.addEventListener(Event.MOUSE_LEAVE, cursorHide);
    function cursorHide(evt:Event):void {
    var currFrame = MC_1.currentFrame;
    if (CCW == true) {  //it is true in this case
      movStart = (50 - currFrame);
    else {
      movStart = currFrame;
    if (movStart>25) {
      MC_1.prevFrame();
    // removed swapChildren(MC_1, MC_2); // This is the part I removed
    // removed MC_2.gotoAndPlay(movStart);
    else {
      MC_1.gotoAndPlay (movStart);
    And if I leave the stage on the part where movStart is indeed >25
    Nothing happens,
    So I guess this is not what you meant
    Subject: Action Script 3 how to copy images from another MC in reversed order??
    I cannot direct you in the loading of the images approach, it will be too complicated, and will probably not work anyways... when you move away from a frame that has dynamic content, you lose the content.  So basically, there is nothing practical in taking that approach.
    I do niot understand what the problem will be with the enterFrame/prevFrame approach. If everything you can do with the mouse is already used (which I doubt) by the first mc, then there is nothing else you can do with this file.  You probably just need to rethink your control scheme.  You should search Google for "AS3 slideshow tutorial", and to lighten up your design, add "XML" in that search.
    >

  • My I-Pod plays all podcast in reverse order such as 3.2.1 no matter how I arrange them in I-Tunes.  How do I get my I-Pod to play in the proper 1,2,3 sequence?

    My 3rd gen I-Pod plays all podcast in reverse order, even if I manually try to load it.  I will only automatically play in 3,2,1 order.  Even brought it to the Apple Store and they couldn't figure it out either.  Even bought another I-Pod and still plays in reverse order.  Any ideas out there?
    Thanks in advance for any help, Ty

    They did not order the podcasts correctly in the playlist then.  Several people, including myself, have been able to play podcasts in sequential order. 
    When viewing the playlist in iTunes, look to the far left of each episode. There should be a number next to it.  This is the ordering of the playlist.  Sort the playlist in sequential order and view the numbering along the leftmost column and see if the ordering matches up as desired. If they don't, you'll need to drag and drop tracks until they are.
    Once the ordering is as desired, right->click on the playlist and choose Copy to Play Order. Then resync the playlist over to your iPod.
    B-rock

  • How can I get iTunes to NOT fill iPod shuffle in reverse order?

    Any ideas?? iTunes loads my iPod shuffle in the reverse order when I drag tracks from my Music Library to my iPod. This is important because I like to listen to audiobooks during my workouts. All I want is to listen to the first track first and not the last track!
    It seems as if the issue arose when I updated to the latest iTunes (7.1.1.5). The previous version worked just fine for me.
    I reloaded a book that I listened to previously. Although it loaded up several weeks ago OK, now it too loads the tracks in the reverse order.
    Thank you in advance for your suggestions!!
      Windows XP Pro  

    After a couple of days, I'm noticing that the repeat(ing) offenders have more than 10 episodes, and seem to keep repeating them every time I sync.
    They only show once in my phone and in the iTunes Podcasts, but through iTunes and looking at what's in my phone is when I see the repeats.
    Even after I've marked a podcast as played, and deleted it from within my phone, as well as telling iTunes to delete the played episodes, it still shows multiples of the played episodes.
    There doesn't seem to be any rhyme or reason to it either. They aren't the newest ones either.

  • Commands to Print Word Document in Reverse Order and Only Evens or Odds

    I have an HP Photosmart printer that doesn’t have automatic duplex printing, so instead of manually printing the odds and then flipping the paper and printing the evens, I decided to write a script (I’m very new to script writing, so go easy on me):
    tell application "Microsoft Word"
    print out active document print out page type print odd pages only
    end tell
    display dialog "After the papers finish printing and after you place the papers back into the printer, rotated 180º, click OK." buttons {"OK"} ¬
    default button "OK" with icon note
    set the user_choice to the button returned of the result
    if the user_choice is "OK" then
    tell application "Microsoft Word"
    print out active document print out page type print even pages only
    end tell
    end if
    The only things that are working are the printing and the dialog box. The odd pages and even pages scripts don’t seem to work (though I read this passage from Guy Hart-Davis’s +AppleScript: A Beginner’s Guide+ http://books.google.com/books?id=9uBeokAwNLsC&lpg=PA303&ots=ICfmxTfG-W&dq=apple% 20script%20print%20odd%20number%20pages&pg=PA303#v=onepage&q&f=false) and I can’t find any command that will print my even pages in a reverse order. Any help would be so much appreciated.
    Message was edited by: mattshank

    I believe I got the script to print the second round in reverse order, but I still can’t get it to print odd pages only and even pages only.
    tell application "Microsoft Word"
    print out active document
    end tell
    display dialog "After the papers finish printing and after you place the papers back into the printer, rotated 180º, click OK." buttons {"OK"} ¬
    default button "OK" with icon note
    set the user_choice to the button returned of the result
    if the user_choice is "OK" then
    tell application "Microsoft Word"
    print with properties {print reverse}
    end tell
    end if

Maybe you are looking for