Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2007
    Posts
    265

    Unanswered: retrieving max(date) and corresponding value in a query

    Hi,

    I have a table with these columns ---


    ID READINGVALUE DATEADDED
    ----------- ------------------------ --------------------------
    4328 5 2007-09-21-19.33.36.558139
    4328 6 2007-10-24-17.25.32.255380
    4328 7 2008-01-08-19.43.58.038657


    I want to retrieve the readingvalue corresponding to MAX(DATEDADDED). Is this the most efficient way to retrieve it --

    db2 "select * from table1 where id=4328 and DATEADDED=( SELECT MAX(DATEADDED) FROM table1 where id=4328)"

    ID READINGVALUE DATEADDED
    ----------- ------------------------ --------------------------
    4328 7 2008-01-08-19.43.58.038657

  2. #2
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Lightbulb Linear Maximum

    Most effective this one, which I am using for 3 years, already.

    I called this operation as "Linear Maximum":

    Code:
    SELECT 
          INT(SUBSTR(MAX(CHAR(DATEADDED) || CHAR(READINGVALUE)),27))
    from table1 where id=4328
    Lenny

Posting Permissions

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