Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get most recent date without subquery 1

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
NZ
Hi all,

Another question on getting a record for the most recent date...

I have a list of prices in a table and I need to get the most recent price for a specified item.

I've got the following query which correctly brings back the most recent price:

Code:
select priceID, price_date, price_value 
from real_time_prices 
where priceID = 1003 
	and price_date = (select max(price_date) from real_time_prices  where priceID = 1003)

Would I be able to optimize this query so I don't need to have the select MAX() subquery?

Thanks as always


Craftor
:cool:
 
Are you trying to return just one row?

Code:
select Top 1 priceID, price_date, price_value
from real_time_prices
where priceID = 1003
Order By Price_Date DESC


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
Doug needs a new pair of shoes, please click an ad link.
 
Thanks that's the sort of thing I was looking for!

Craftor
:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top