I have two tables, tblWorkOrder and tblSubWorkOrder. There is a one to many relationship between them. I want to pull the work order ID from the tblWorkOrder table and the Acres field from the tblSubWorkOrder table. Here's my query:
SELECT tblWorkOrder.pkWorkOrderID, tblSubWorkOrder.Acres
FROM tblWorkOrder INNER JOIN tblSubWorkOrder ON tblWorkOrder.pkWorkOrderID = tblSubWorkOrder.WorkOrderID
What I get is this:
WORKORDERID___ACRES
1_______________55
1_______________120
1_______________87
2_______________400
3_______________40
3_______________80
3_______________200
ETC.
I get multiple records per work order because different subworkorders under the same work order can have different acreages associated with them.
What I want is just one record returned for each work order ID. Preferably, the one record I would want to keep for each work order is the one that has the highest acreage. Thus, this is what I'm after:
WORKORDERID___ACRES
1______________120
2______________400
3______________200
ETC.
How do I do this in SQL?
Thanks,
Duluter
SELECT tblWorkOrder.pkWorkOrderID, tblSubWorkOrder.Acres
FROM tblWorkOrder INNER JOIN tblSubWorkOrder ON tblWorkOrder.pkWorkOrderID = tblSubWorkOrder.WorkOrderID
What I get is this:
WORKORDERID___ACRES
1_______________55
1_______________120
1_______________87
2_______________400
3_______________40
3_______________80
3_______________200
ETC.
I get multiple records per work order because different subworkorders under the same work order can have different acreages associated with them.
What I want is just one record returned for each work order ID. Preferably, the one record I would want to keep for each work order is the one that has the highest acreage. Thus, this is what I'm after:
WORKORDERID___ACRES
1______________120
2______________400
3______________200
ETC.
How do I do this in SQL?
Thanks,
Duluter
Last edited: