Subject Re: SQL Query Help - more
Author Svein Erling Tysvær
Well Erik, maybe you want

Select ET1.PrID, ET1.Description, ET1.Unit, ET1.Qty, ET1.Price,
ET1.SaleDate
from ErikTable ET1
where not exists(
select (*) from ErikTable ET2
where ET2.PrID = ET1.PrID
and ET2.SaleDate > ET1.SaleDate)

This will get you records for the last SaleDate for every PrID. If
SaleDate isn't unique, you will have to add something unique to the
subselect to only get the last record.

By the way, this is the correct list for this type of questions.

HTH,
Set

--- In firebird-support@yahoogroups.com, "Erik Raul Chan Silveira" wrote:
> > > I would like your help with a query, I have the next data:
> > >
> > > ProductID SaleDate (m/d/Y)
> > > Pr1 05/05/2005
> > > Pr1 06/01/2005
> > > Pr2 01/01/2005
> > > Pr2 10/15/2005
> > > ...
> > > Pr1 10/29/2005
> > > Pr2 10/16/2005
> > > ...
> > > Pr3 10/01/2005
> > > ...
> > >
> > > I wanna obtain a resulset with all products and its last (most
> > recent)
> > > SaleDate,
> > > something like:
> > > ProductID SaleDate
> > > Pr1 10/29/2005
> > > Pr2 10/16/2005
> > > Pr3 10/01/2005
> > >
> It works if table has only those 2 fields,
> but the table has more columns: PrID, Description, Unit, Qty, Price,
> SaleDate.
> So, Im interested in obtain the complete 'LAST' row of every sold
> product.
>
> Again, thanks in advance, my best 4 U,
>
> Erik
> ____
>
> PD: Im searching for a SQL lists, forums ...