Try this (not tested). UPDATE ( SELECT [L].[alt_end], [T].[source elevation] FROM [Splitted_Lines] AS [L] INNER JOIN ( SELECT [ID] AS [target ID], FIRST([elevation]) AS [source elevation] FROM ( SELECT [A].[ID], [B].[elevation] FROM ( SELECT * FROM [Splitted_Lines] WHERE [no_ponceau] = "Doris_05" AND [situation] = "aval" ) AS [A] INNER JOIN [EndPoints] as [B] ON [A].[no_ponceau] = [B].[no_ponceau] AND Touches([A].[ID], [B].[ID]) ORDER BY [B].[elevation] DESC ) GROUP BY [ID] ) AS [T] ON [L].[ID] = [T].[target ID] ) SET [alt_end] = [source elevation] ; I have rearranged some things. Table A is pre-filtered, since that is faster than filtering after the expensive join. Touches is changed to use object IDs, so that it is controlled by the location precision of the (first) drawing, whereas Geom (I) would the use default precision of 0.000001.
|