x

latest price and product name

i have two tables 1. Product and 2.Product_Price

The tables have below columns 1.Product(ID PK,Product) 2.Product_Price(ID FK,Price,date)

the two ID is relationship.

i need the query for latest price and product name.

more ▼

asked Jul 19, 2012 at 12:25 PM in Default

avatar image

karthik84vb
28 2 3 5

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

How about

 ;WITH CTE AS
 (
 SELECT Product, Price, ROW_NUMBER() OVER (PARTITION BY P.ID ORDER BY PP.Date DESC) Rownum
 FROM  Product P INNER JOIN Product_Price PP ON P.ID = PP.ID
 )
 
 SELECT * FROM CTE WHERE Rownum = 1
more ▼

answered Jul 19, 2012 at 12:32 PM

avatar image

Usman Butt
13.9k 6 13 21

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1067

asked: Jul 19, 2012 at 12:25 PM

Seen: 477 times

Last Updated: Jul 19, 2012 at 12:32 PM

Copyright 2016 Redgate Software. Privacy Policy