I'm a complete beginner to Postgresql and Postgis and I can't figure how to do this:
I have 3 tables, T1, T2 and T3. T1 and T2 have ID as common column. T2 and T3 can be joined on the geom column. T1 and T3 can't be joined.
In table 1, I have all the river names of my country. In table 3, I have all my data points (bound to table 2 by the geom column).
What I want is to add a column name to T3 which will tell me on what river this point lies.
I can bind T1 and T2 to have the name in T2. But I don't know how to continue and have this on T3.
What I have done, and this is really bad I know, is this:
ALTER TABLE T3 AS
WITH part1
(
SELECT *
FROM T3
INNER JOIN T2 ON (the_geom = st_transform(geom_T3, 2154))
),
part2 AS
(
SELECT *
FROM T1
INNER JOIN T2 ON T2.id = T1.id
),
SET T1.name AS id
FROM Part2;
Obviously that doesn't work at all.
I know that's a basic query so if you don't want to lose your time I'll understand :)
Also, I'm not English so forgive me for my mistakes.
Thank you