Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
liuyang
Starting Member
6 Posts |
Posted - 2003-01-29 : 22:54:47
|
| Dear experts:i have a table call productpricehistory which consists three columnsproductID,PublishDate,Pricethere are many records with same productID but different PublishDateso how to get a list with the latest publishdate for each productthank you |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-01-29 : 23:05:17
|
| SELECT ProductID, Max(PublishDate) FROM ProductPriceHistoryGROUP BY ProductID |
 |
|
|
liuyang
Starting Member
6 Posts |
Posted - 2003-01-29 : 23:13:30
|
| Thanks but if i also want to get the latest price for each product then what should i do?there is an error of: Column 'Price' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.when i add price in |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-01-29 : 23:13:52
|
| You probably want the price as well?SELECT ProductID, PublishDate, PriceFROM ProductPriceHistory t1where t1.PublishDate = (select max(t2.PublishDate) from ProductPriceHistory t2 where t2.ProductID = t1.ProductID)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
liuyang
Starting Member
6 Posts |
Posted - 2003-01-29 : 23:20:46
|
| Thank you very much |
 |
|
|
|
|
|