Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Aug 2013
    Posts
    7

    Unanswered: How to retrieve last record in a table.

    Hi,
    I have a bulk of employee records, i want to retrieve 1st record and last record in employee table how to retrieve the record please help me..

  2. #2
    Join Date
    Dec 2012
    Location
    Logan, Utah
    Posts
    163
    Not without seeing some DDL.

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Define: "first"
    Define: "last"

    The physical order of data in a database has no meaning.

    As LinksUp stated: we need to know a lot more about your problem first. Start by posting your table structure, some example data, the desired result from your sample data and an explanation as to why you want these records in the result.
    George
    Home | Blog

  4. #4
    Join Date
    Aug 2013
    Posts
    7
    Hi Gvee,
    Please give me some example.
    Last edited by sapthagiris; 08-19-13 at 07:37.

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    how do you know which record was the first
    how do you know which record will be the last
    what sequence are they in
    what mechanism do you think exists (or will need to exist) so that you can identify when rows are added.
    is it a sequential number
    is it a timestamp (date and time of when the row was added)
    is it some other form of code.
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by sapthagiris View Post
    I have a bulk of employee records, i want to retrieve 1st record and last record in employee table how to retrieve the record please help me..
    From the perspective of the database engine, all of the rows in a table are simply a jumble... There is no "first" or "last" until you put some kind of order on the rows.

    Since the order does not matter to the database engine, pick any row at random and call it both the first and the last row.

    If you want to put some kind of order on your rows, then you have a different kind of problem, and "first" and "last" then mean something. This is the problem that gvee, Linksup, and healdem are trying to help you solve.

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

  7. #7
    Join Date
    Aug 2013
    Posts
    7
    Hi,
    i have Employee table there are 2 fields Name and salary. How to retrieve first row and last row using index please help any one..

  8. #8
    Join Date
    Dec 2012
    Location
    Logan, Utah
    Posts
    163
    Quote Originally Posted by sapthagiris View Post
    Hi,
    i have Employee table there are 2 fields Name and salary. How to retrieve first row and last row using index please help any one..
    Did you read ANY of the posts in response to your original question? You have not provided one bit of information that was requested or is helpful.

    Please provide some DDL with indexes. If this is an Employee table it probably has more than one index. So we would need to know which index you want to get the first and last record. Data would not hurt either.

    If you cannot provide this minimal information then your chances of getting any kind of answer is non existant.

  9. #9
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Quote Originally Posted by sapthagiris View Post
    Hi,
    i have Employee table there are 2 fields Name and salary. How to retrieve first row and last row using index please help any one..
    First row and last row according to what? Name, or Salary? Ascending or Descending?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  10. #10
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Quote Originally Posted by blindman View Post
    First row and last row according to what?
    Index, of course.

  11. #11
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Quote Originally Posted by corncrowe View Post
    Index, of course.
    "What index?", would be the clarifying question.

    Of course.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  12. #12
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Since there are only two fields (columns) then the index is either name or salary. Or both. First record would be ascending order. Last record would be descending order. Union two select statements would satisfy both criteria. Order by asc or desc.

    Edit: Changed fields to columns so Joe won't come back and choke me.
    Last edited by corncrowe; 08-22-13 at 14:03.

  13. #13
    Join Date
    Jan 2013
    Posts
    354
    Provided Answers: 1

    Lol!

    Changed fields to columns so Joe won't come back and choke me.

    Let's give up on this guy until he reads a book on RDBMS or set theory. Remember the rule about arguing with a pig.

  14. #14
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Interesting enough, I just happened to come across one term paper I wrote in college about designing database management systems, circa 1984. Of course back then we had CICS.

  15. #15
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Quote Originally Posted by corncrowe View Post
    Since there are only two fields (columns) then the index is either name or salary. Or both.
    Which still leaves my question unanswered, does it not?

    Quote Originally Posted by corncrowe View Post
    First record would be ascending order. Last record would be descending order.
    Not at all. Salary might be sorted ascending or descending, and either direction could be considered "first".
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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