IT Guy
asked on
SQL - Subtract OLDEST record in TABLE 2 from NEWEST record from TABLE 1 (Without Cursor)
The best way I can explain my question is with the graphic below.
I want to select the OLDEST record from TABLE 2 and the LATEST record from TABLE 1 and find the difference in a query. Obviously I can loop through my items and select TOP 1 from both tables and do the calculation, but as usual, this takes too long.
I want to select the OLDEST record from TABLE 2 and the LATEST record from TABLE 1 and find the difference in a query. Obviously I can loop through my items and select TOP 1 from both tables and do the calculation, but as usual, this takes too long.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You have taught me something today. I didn't fully understand the WITH statement or the ROW_NUMBER function until today, and you taught me.
After a little fiddling around it worked, and I'm very grateful. Thank you.