|
Posted by Roy Harvey (SQL Server MVP) on 10/12/07 11:11
On Thu, 11 Oct 2007 23:47:18 -0700, blackpuppy <mingzhu.z@gmail.com>
wrote:
>I would like to use the following SQL statement to get the latest
>comment for all products.
>
>SELECT PRODUCT_ID, COMMENT, UPDATED_ON
>FROM PRODUCT_COMMENT
>GROUP BY PRODUCT_ID
>HAVING UPDATED_ON = MAX(UPDATED_ON)
SELECT PRODUCT_ID, COMMENT, UPDATED_ON
FROM PRODUCT_COMMENT as A
WHERE UPDATED_ON =
(SELECT MAX(UPDATED_ON)
FROM PRODUCT_COMMENT as B
WHERE A.PRODUCT_ID = B.PRODUCT_ID)
GROUP BY PRODUCT_ID
Roy Harvey
Beacon Falls, CT
Navigation:
[Reply to this message]
|