You mention that the results are ordered correctly in your database but that the order is altered by your SELECT statement. It might be helpful to know that one of the features (no, really, it's a feature) of most relational databases is that a result set from a query will be in an indeterminate order unless you ask for it to be ordered. (Some RDBMS's might have a feature to get around this; since I don't know what you're using and spend most of my time in SAS and DB2, so I'm not sure.)

Ideally, you will have a column in the table on which you can order, but if you don't, do not despair -- most RDBMS's will provide the table in its "natural" (physically stored) order if you do "select * from table". You might then need to add another counter column (or use an RDBMS-specific function to get to it) and either run SQL against that or just do your processing in straight Perl.

Hope this helps.


In reply to Considerations on ordering by cebrown
in thread Sorting by johnirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.