SELECT Consumer.*, Status.*, Hours.AppHours FROM Consumer JOIN Status on Consumer.ConPK=Status.ConFK LEFT OUTER JOIN Hours on Consumer.ConPK=Hours.ConFK WHERE Status.Date = (SELECT MAX(Stat2.Date) FROM Status Stat2 WHERE Stat2.ConFK = Consumer.ConPK GROUP BY Stat2.ConFK) AND Status.Type = "Approved" AND Hours.Date = (SELECT MAX(Hours2.Date) FROM Hours Hours2 WHERE Hours2.ConFK = Consumer.ConPK GROUP BY Hours.PK)
I actually can't get this to run without errors. Interpolating, I **think** you meant:
SELECT Consumer.*, Status.*, Hours.AppHours FROM Consumer JOIN Status on Consumer.ConPK=Status.ConFK LEFT OUTER JOIN Hours on Consumer.ConPK=Hours.ConFK WHERE Status.Date = (SELECT MAX(Stat2.Date) FROM Status Stat2 WHERE Stat2.ConFK = Consumer.ConPK AND Status.Type = "Approved" GROUP BY Stat2.ConFK) AND Hours.Date = (SELECT MAX(Hours2.Date) FROM Hours Hours2 WHERE Hours2.ConFK = Consumer.ConPK GROUP BY Hours.PK)
However, I get "Function missing )" on the last subquery on this this, and neither intellisense nor I can find any unmatched parens.
Also, the first subquery is grouping on the Status table FK, while the second subquery groups on the Hours table PK. I think they should both group on the same key, but I don't understand which one that should be.
Thanks.
Ken