VERY URGENT: How to read only the newest data

  • How to get only the last elements (the newest in term of date)?

    In a table which get these fields code, datetime, price (The PK is Code + Datetime) I need to get only the newest code elements.

    THANK YOU VERY VERY MUCH IF YOU MAY HELP ME QUICKLY.

  • Hi,

    I am assuming here you want the price for the latest datetime associated with a code.

    Try :

    select code, datetime, price

    from tablename t1

    where datetime = ( select max(datetime)

    from tablename t2

    where t2.code = t1.code)

    If what you want is the latest date for a code/price combination then try :

    select code, datetime, price

    from tablename t1

    where datetime = (select max(datetime)

    from tablename t2

    where t2.code = t1.code

    and t2.price = t1.price)

    Cheers

    Tony Healey

    http://www.sqlcoder.com - Code generation for SQL Server 7/2000

    Regards

    Tony Healey

    http://www.SQLCoder.com - Code generation for SQL Server 7/2000


    Regards

    Tony Healey
    www.SQLCoder.com - Free Code generation for SQL Server 7/2000

  • Thank you very much for your help.

    It really did help me. Thanks a lot.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply