Sample Header Ad - 728x90

Add row from table B based on minimum distance between table A and B

0 votes
1 answer
168 views
I am a beginner with PostgreSQL and have two tables A and B, both with multiple columns, including a point column (geom): TableA includes a given 'ID', geom, etc , TableB is a "DB" of locations with a 'name' column, geom, etc... **Need to find for each TableA.id what is the the 'name' (row columns) and distance of the closest location in TableB.** already could calculate the distance between all points of TableA and TableB with : ST_DistanceSpheroid(pointA,pointB,[SPHEROID]) But the best could build so far, is a select query where provides for each TAbleA.ID all distances and respective names from TableB - does not find the minimum for each ID only. **While needed to have the new calculated columns (distance and name) added to Table A.** It is not yet clear to me how to work with data output when using "select" vs an actual table data output. or use of views.
Asked by domiho1 (25 rep)
Aug 13, 2022, 05:51 PM
Last activity: Aug 13, 2022, 10:52 PM