J
jcook4now
All,
I would like to have a query with a correlated subquery that will
give me the records associated with the minimum of a calculated value.
I am calculating the difference between the depth in one table
(Actual.Depth) and the depth in another (New.AbsDepth) by joining the
tables and using the calculation ABS(Actual.Depth-New.AbsDepth). My
goal is to get all the records in Actual associated with the minimum of
this calculation for a given EventID and AbsDepth in the table New.
The following query returns ALL the differences:
SELECT actual.eventID, new.absdepth, Actual.depth,
abs(Actual.depth-new.absdepth) AS Difference, actual.temp, actual.ph
FROM new, actual
WHERE new.EventID=actual.EventID;
I can then use a second query to get the records associated with the
minimum Difference. However, the query above becomes extremely slow
with large datasets and I'm assuming there is a way to use a
correllated subquery to accomplish the same goal.
Any ideas?
Jeff
I would like to have a query with a correlated subquery that will
give me the records associated with the minimum of a calculated value.
I am calculating the difference between the depth in one table
(Actual.Depth) and the depth in another (New.AbsDepth) by joining the
tables and using the calculation ABS(Actual.Depth-New.AbsDepth). My
goal is to get all the records in Actual associated with the minimum of
this calculation for a given EventID and AbsDepth in the table New.
The following query returns ALL the differences:
SELECT actual.eventID, new.absdepth, Actual.depth,
abs(Actual.depth-new.absdepth) AS Difference, actual.temp, actual.ph
FROM new, actual
WHERE new.EventID=actual.EventID;
I can then use a second query to get the records associated with the
minimum Difference. However, the query above becomes extremely slow
with large datasets and I'm assuming there is a way to use a
correllated subquery to accomplish the same goal.
Any ideas?
Jeff