x
login about faq Site discussion (meta-askssc)

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 '12 at 12:25 PM in Default

karthik84vb gravatar image

karthik84vb
28 1 4

(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 '12 at 12:32 PM

Usman Butt gravatar image

Usman Butt
13.8k 6 8 14

(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



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x914

asked: Jul 19 '12 at 12:25 PM

Seen: 262 times

Last Updated: Jul 19 '12 at 12:32 PM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.