Table structure:
create table fruit (
id int identity(1,1),
name varchar(max)
)
create table fruit_allocation (
id int identity(1,1),
fruit_id int references fruit(id),
customer_id int references store(id),
amount float,
)
create table measurement (
fruit_allocation_id int references fruit_allocation(id),
measurement_date datetime,
measurement float,
)
Each fruit can be allocated to more than one client by creating a fruit_allocation record. Each fruit_allocation record can have several dimensions.
I want to choose the last dimension for each fruit_allocation based on the fruit id
So far I have the following:
select *
from measurement
where fruit_allocation_id in (select id
from fruit_allocation
where fruit_id = 10)
This returns all dimensions for this fruit, I just want to return 1 dimension to the fruit plane.
source
share