Last 3 dates for each product

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a database where users update a number of products. They include an
update date each time.

How can I create a query to show only the last 3 updates - based on the
update date - of each product?

Thanks,
 
Try something along the lines of
SELECT productId, updateDate FROM MyTable T1
WHERE updateDate IN (SELECT TOP 3 updateDate FROM MyTable T2 WHERE
T2.productId = T1.productId ORDER BY updateDate DESC);

Hope This Helps
Gerald Stanley MCSD
 
Hi Gerald,

Sorry for my ignorance, but what are T1 and T2 refering to? The update date
is only in one table.

Thanks again,

Marc
 
T1 and T2 are table aliases. The correct syntax is FROM MyTable AS T1 and
FROM MyTable AS T2. The AS is an optional qualifier that most experienced
developers leave out. In the example SQL I provided, they distinquish
between the two logical instances of the same physical table that I have
called MyTable.

Hope This Helps
Gerald Stanley MCSD
 
Back
Top