Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Get the latest record of a set
Thu, Oct 25 2007 8:41 AMPermanent Link

"Juan J Velazquez Garcia"
Hello,

For two tables:

PRODUCTION_ORDER (ID, DUE_DATE, ID_STATUS , OPEN)

STATUS (ID, DATE, STATUS)

The status table stores a history of production order's status.

How can I get the latest status for a production order.


SELECT
 PO.ID, PO.DUE_DATE, S.DATE, S.STATUS
FROM
 PRODUCTION_ORDER PO, STATUS S
WHERE
 OPEN=TRUE AND PO.ID_STATUS=S.ID

But I want only the latest Status.



Thanks in advance,
Juan
--
Fri, Oct 26 2007 3:57 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Juan,

<< How can I get the latest status for a production order. >>

Try this:

SELECT
 PO.ID, PO.DUE_DATE, S.DATE, MAX(S.STATUS) AS STATUS
FROM
 PRODUCTION_ORDER PO, STATUS S
WHERE
 OPEN=TRUE AND PO.ID_STATUS=S.ID
GROUP BY ID, DUE_DATE, DATE

--
Tim Young
Elevate Software
www.elevatesoft.com

Image