LearnItFirst User Forum

SQL Server 2008 DBA Training Videos
Welcome Guest Search | New Posts | Members | Log In | Register

returning partially distinct/unique rows Options
andrej351
Posted: Monday, May 11, 2009 9:02:26 PM
Rank: Newbie

Joined: 4/27/2009
Posts: 3
Points: 9
Where do you live?: Australia
Hi all,

I need to create a query which groups by two columns and returns an additional column based on a condition.

For example, say I've got the following columns:

ProductCode | SerialNumber | Quantity | DatePurchased | CustomerID

and the table contains duplicate combinations of ProductCode and SerialNumber with differing Quanitites and Purchase Dates. I'd like to return the ProductCode, SerialNumber and the Quantity for the row with greatest (most recent) value for DatePurchased. To further complicate things this must be done for all rows where CustomerID = 'xxx'.

Any ideas???

Any help appreciated.
Cheers.
bklr
Posted: Tuesday, May 12, 2009 1:37:52 AM

Rank: PFY

Joined: 1/21/2009
Posts: 27
Points: 81
Where do you live?: India
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=125498
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.