Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    18

    Unanswered: How to select first and last row data ?

    Hi..

    Below is sample of my data:-
    E1234
    C1234
    X1234
    Z1234
    S1234
    B1234

    Based on data, how could i selct first and last row of the data ?. The resuler must be:-
    First row: E1234
    Last row: B1234

    I have tried used max and min query but it will be sort the data A-Z.

    Please advise..

    Thank you,
    Baharin

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    no can do, sorry
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    What determines the order of the rows presented?

    Since rows in a table have no inherant order, we can assume any order so just select the first two rows, the min and max values, the last two rows, or anything else that is convenient. If you want to put some specific order on the rows, then things are a little trickier, but no big deal.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    As Pat P says you need to establish what makes the earliest row and what makes the latest row. so whatever it is (and I'm expecting its going to be a another column... probably some for of date/time or batch + sequence ID)
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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