This is the SQL statement like :
SELECT InoiceId, InvoiceNumber, Amount
FROM Invoice INNER JOIN
( SELECT ID = Max(Id), StatusId
FROM InvoiceStatus
Group By StatusId) AS t
WHERE T.StatusId IN (1,6)
I tried with IEntityRelation and I cannot pass a sub query to the relation