0

I have three tables in Postgresql, each table with one layer of lines. I want to show the path of an initial line to another final. Is it possible executing a SQL query? Thanks

My three tables are connected:

Table cables - gid, id, the_geom

Table tubes - gid, id, cable_id, the_geom

Table fibers - gid, id, tube_id, the_geom

If I select the fiber id=1 I want to know (and see in map) the way starting in fiber 1 until the beginning (fiber - tube - cable)

2
  • Welcome to gis.SE. Its probably possible, but to show you how it might work (e.g with a sample query), we'll need to see the schema for the tables and possibly the data if that schema isn't very descriptive. Can you update your question (just click "edit" above) to include this information?
    – BradHards
    Commented Apr 12, 2013 at 10:30
  • Do you wanna join all three tables ? You can create SQL view and add it from "add postgis layer" to qgis. Im not sure what you want Commented Apr 12, 2013 at 10:39

1 Answer 1

2

use extention "DB Manager" and there maybe type the SQL-Query (one layer):

    select gid, id, 'cable' as type, the_geom from cables a join tubes b join fibers c on b.id = c.tube_id on a.id = b.cable_id where c.id = 1
    union
    select gid, id, 'tube' as type,`the_geom from tubes d join fibers e on d.id = e.tube_id where e.id = 1
    union
    select gid, id, 'fiber' as type, the_geom from fibers where id = 1;

or type every select (without union) to get three layers.

3
  • How can I save a layer with that instrunctions? You said to "type every select". Where type the queries? The problem is, I want to select a line and it show me the way until the beggining (origin line). cables -> tubes -> fibers ---cable 1---->------tube 1---->-----fiber 1-----> this is an example of route fiber 1 origin in tube 1, and tube 1 origin in cable 1 Thank you Commented Apr 12, 2013 at 16:31
  • In menue click at "Database" and choose "DB Manager". Connect to database and click at "SQL window". Here it's possible to enter SQL-queries and adding as layer.
    – Wolf
    Commented Apr 13, 2013 at 16:59
  • It don't accept three registers from three tables, the union don't function Commented Apr 15, 2013 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.