Subject | How to find record ID table which contains item price with datetime and items ID |
---|---|
Author | piotr.olszewski@ymail.com |
Post date | 2012-03-01T11:16:17Z |
Hi everone!
I have two tables.
One with items (ID, Items name etc.)
second one which conteins tiemstamp and price and of course ID of the items.
What I need is to find last items price from selected period.
Here's how i do it now:
select
tblItems.item_ID,
tblItems.Item_Name,
(Select tblPrices.Price from tblPrices where tblPrices.DateTime =
(select max(tblPrices.DateTime) from tblPrices
where tblPrices.Item_id = tblItems.item_ID and tblPrices.DateTime
between '2011-01-01' and '2011-06-30')
and tblPrices.Item_id = tblItems.item_ID) as LastPreis
from tblItems
order by tblItems.Item_Name
and of course it works.
But is there any easiest way??
Piotr
I have two tables.
One with items (ID, Items name etc.)
second one which conteins tiemstamp and price and of course ID of the items.
What I need is to find last items price from selected period.
Here's how i do it now:
select
tblItems.item_ID,
tblItems.Item_Name,
(Select tblPrices.Price from tblPrices where tblPrices.DateTime =
(select max(tblPrices.DateTime) from tblPrices
where tblPrices.Item_id = tblItems.item_ID and tblPrices.DateTime
between '2011-01-01' and '2011-06-30')
and tblPrices.Item_id = tblItems.item_ID) as LastPreis
from tblItems
order by tblItems.Item_Name
and of course it works.
But is there any easiest way??
Piotr