Hi,
I have 2 tables with dates like so:
[tt]TableA
-------
ProductID Date Value
TRUCK 16/10/08 $5
TRUCK 10/10/08 $4.5
TRUCK 03/10/08 $4
CAR 15/10/08 $4.25[/tt]
[tt]TableB
-------
SaleId Customer ProductID SaleDate
1010 Customer1 TRUCK 11/10/08
1011 Customer2 TRUCK 11/10/08
1012 Customer3 TRUCK 05/10/08
1013 Customer1 CAR 15/10/08[/tt]
Now .. I want to select all the sales from TableB and work out what the price was at the time of sale.
eg. Sale 1010 should have been for $4.50
Sales 1012 should have been for $4 as it took place before the price rise.
SELECT b.SaleId,b.Customer,a.Value
FROM TableA a,
TableB b
WHERE a.ProductID = b.ProductID
and a.SaleDate = ?
I have 2 tables with dates like so:
[tt]TableA
-------
ProductID Date Value
TRUCK 16/10/08 $5
TRUCK 10/10/08 $4.5
TRUCK 03/10/08 $4
CAR 15/10/08 $4.25[/tt]
[tt]TableB
-------
SaleId Customer ProductID SaleDate
1010 Customer1 TRUCK 11/10/08
1011 Customer2 TRUCK 11/10/08
1012 Customer3 TRUCK 05/10/08
1013 Customer1 CAR 15/10/08[/tt]
Now .. I want to select all the sales from TableB and work out what the price was at the time of sale.
eg. Sale 1010 should have been for $4.50
Sales 1012 should have been for $4 as it took place before the price rise.
SELECT b.SaleId,b.Customer,a.Value
FROM TableA a,
TableB b
WHERE a.ProductID = b.ProductID
and a.SaleDate = ?