Select Top1 from multiple-column query for each product ID
<p>I have a query in SQLServer that returns the last entry in our stock of a given product, as well as many other columns. Something like:</p>

<pre><code>SELECT
TOP(1) EntryDate,
EntryPrice,
TaxID,
TransportCost,
...

FROM
StockEntries

WHERE
ProductID = @ID

ORDER BY
EntryDate DESC
</code></pre>

<p>I cannot use MAX to get the last entry because sometimes it returns duplicate rows (when there are two entries at the same day).</p>

<p>I would like to execute this query for every product we have. I could do this if the query returned only 1 row, such as:</p>

<pre><code>SELECT
ProductID p,
(
    SELECT
    TOP(1) s.EntryDate

    FROM
    StockEntries s

    WHERE
    s.ProductID = p.ProductID

    ORDER BY
    s.EntryDate DESC
)

FROM
Products p
</code></pre>

<p>But as it returns multiple rows, I cannot see a straight way to do this. </p>

<p>Any ideas?</p>