Results 1 to 7 of 7

Thread: Last Function

  1. #1
    Join Date
    Jan 2004
    Posts
    164

    Unanswered: Last Function

    Access has a last function available for when you are grouping on a summary level. What this does is return the last record for that particular grouping. Does sql have function of that nature?

    Example:

    Item_Code Time
    123456 11:40
    123456 11:41
    123456 11:42

    By grouping on item code and using the last function on the Time column, the third record would be returned.



    Item_Code Time
    123456 11:42


    All, help is appreciated.
    Last edited by estefex; 07-10-06 at 18:55.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Last is not as reliable as you may think, and SQL Server doesn't have it. Try Max instead.
    Paul

  3. #3
    Join Date
    Jan 2004
    Posts
    164
    well, i really cannot use max because it will give me a max each cloumn. For example:

    Item Date Time
    12345 7/10/06 11:21
    12345 7/10/06 11:45
    12345 7/12/06 09:45

    If i group on item and use max for date and time i would get

    Item Date Time
    12345 7/12/06 11:45

    I basically need to find a way o get the last record of a set.

    Maybe there is a better way to approach this.

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Last would not behave any differently in Access, so I'm not sure why you asked for the replacement for Last. One way is to join date and time together in one field and do your max on that.
    Paul

  5. #5
    Join Date
    Jan 2004
    Posts
    164
    Quote Originally Posted by pbaldy
    Last would not behave any differently in Access, so I'm not sure why you asked for the replacement for Last. One way is to join date and time together in one field and do your max on that.
    I think that would probbaly be my best bet. Thanks for all your help.

  6. #6
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    No problem. BTW, here's more info on why First/Last are not necessarily reliable anyway:

    http://support.microsoft.com/kb/208190/en-us
    Paul

  7. #7
    Join Date
    Jan 2004
    Posts
    164
    Quote Originally Posted by pbaldy
    No problem. BTW, here's more info on why First/Last are not necessarily reliable anyway:

    http://support.microsoft.com/kb/208190/en-us

    Sweet, I really appreciate all the help and notes.

Posting Permissions

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