Wednesday, March 25, 2009

Maximum Date in a group of records

Sort command and groupins i am ok but i need to select only the records that
has the latest enddate


eg-: select h.component_fixed_id ,h.date_added,h.factory_price from history_manufacturer_components as h
where manufacturer_code='arv001' and
date_added =(select max(date_added) from history_manufacturer_components where component_fixed_id=h.component_fixed_id)

or
This query returns row(s) with the latest Enddate for each ID but the row
for ID='B' isn't the one you highlighted.


SELECT id, startdate, enddate
FROM SomeTable AS S
WHERE enddate =
(SELECT MAX(enddate)
FROM SomeTable
WHERE id = S.id)