October 4, 2001 at 6:10 am
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.
October 4, 2001 at 1:24 pm
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
October 12, 2001 at 10:30 am
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