QUESTION: I have 2 tables with bike and hike trails of a country (Poland).
Table bicycle_merge
way | route | name |network |osmc_color| state
geometry | text | text |text |text | text
----------------------------------------------------------------
{geo1} |bicycle |szlak1 |ncn |blue |proposed
{geo2} |bicycle |szlak2 |lcn |red |null
{geo3} |bicycle |szlak3 |ncn |green |proposed
{geo4} |bicycle |szlak4 |rcn |blue |proposed
{geo5} |bicycle |szlak5 |lcn |blue |null
{geo6} |bicycle |szlak6 |ncn |yellow |proposed
....and so on
Table hiking_merge
way | route | name |network |osmc_color| state
geometry | text | text |text |text | text
----------------------------------------------------------------
{geo1} |hiking |szlak1 |ncn |blue |proposed
{geo2} |hiking |szlak2 |ncn |red |null
{geo3} |hiking |szlak3 |ncn |green |proposed
{geo4} |hiking |szlak4 |ncn |blue |proposed
{geo5} |hiking |szlak5 |ncn |blue |null
{geo6} |hiking |szlak6 |ncn |yellow |proposed
...and so on
{geo1},{geo2} etc. is a unique geometry of every trail.
Every trail has a unique geometry but sometimes bicycle and hiking routes overlap.
The picture below shows example in QGIS:
I would like to delete the overlapping parts as I already have them in a different database.
EDIT: I have tried a solution suggested by Julia Leder :
create table intersections as
(select st_intersection(b.way, h.way) as overlapping_section
from bicycle_merge b, hiking_merge h
where st_intersects(g.way, h.way));
Not all overlapping lines were detected. I'm not sure why? Here's a picture to show the issue: