In the previous recipe, Creating a routing network for pgRouting, we imported a network layer, built the topology, and finally tested the routing. Building on these results, this recipe will show you how to visualize the routing results on a map in QGIS.
You should first go through the previous recipe, Creating a routing network for pgRouting, to set up the necessary PostGIS tables. Alternatively, you can use your own network tables, but be aware that you may have to alter some of the SQL statements if your table uses different column names.
To visualize the results in QGIS, we can use the DB Manager SQL window, as shown in the following screenshot. The extended query that we use here joins the routing results back to the original network table to get the route link geometries, which we want to display on the map:


As pgr_dijkstra only returns a list with the IDs of the route edges, we need to get the edge geometries from the original network table in order to display the route on the map. Therefore, we join the routing results with the network table on id2 (which contains the edge ID) and the network table's id column.