> > > SELECT Invoice
> > > FROM invoice_status
> > > WHERE Status=1 AND Created=MAX(Created)
> > > GROUP BY Invoice
> > > 
> > > But couldn't get it to work.  "Invalid use of group function"
> > 
> > You need ORDER BY, not GROUP BY.
> 
> I cant get this example to work either.
> I used ORDER BY instead of GROUP BY.

OK, sorry.  I didn't read through it well enough.  Of course it won't work.
You can't put MAX() in a WHERE clause.

Here's the solution:

SELECT Invoice, Status
FROM invoice_status
ORDER BY Created

Put these results into an array like 

$laststatus[$row[0]] = $row[1];

When the loop ends, you'll have an array keyed by the invoice and the value
will be the latest status.  Step through the array and use the invoices
that have status=1.

You could also turn it around with "ORDER BY Created DESC".  You'd need
to put an if statement in the loop, but then you would only need to loop
once over the array.  I guess it depends on whether you want to know the
IDs of the invoices that don't have 1 as their last status.

Leon



------------------------------------------------------------
To subscribe:    [EMAIL PROTECTED]
To unsubscribe:  [EMAIL PROTECTED]
Site:            http://www.working-dogs.com/freetrade/
Problems?:       [EMAIL PROTECTED]

Reply via email to