Sometimes there is a need to join 2 or more database tabels together.

We will show an example below.

We have a map with municipalities and with related data. We want to show the population relative to municipalities, but we dont have population numbers in our table. At the other hand we have another table, which contains population numbers. Therefore we want to join these 2 tables.



Click on "Add PostGIS Layers".



In the list above some tables have "Geometry". This means they contain graphical informations (maps). Other tables do not contain graphics. We need a table with graphics, and one with no graphics. The tables with no graphics are not shown by default. Because of this we need to put "x" in "Also list tables with no geometry".

We mark the 2 tables and click on "Add".



We now got 2 layers into QGIS. If you look at the icons in front of the layer name, you can see, that one of them has graphics, and the other one is only a table without graphics.



Double click on the layer with graphics. In our example it is "Kommunur".

The box "Layer Properties" appears.

In the left panel choose "Joins".

To create a new "Join" click on "+" at the bottom.



The box "Add vector join" appears.

Under "Join layer" choose the layer with no graphics. In our example it is "Kommunur_hagtol".

Under "Join field" and "Target field" choose the fields, which should be joined together in both layers. In our example the field is named "komm_nr" in both layers.

Click on "OK".



Our "Join" now appears in the list of "Joins".

Click "Apply" and "OK".



Now an example that shows, what we can use our "Join" for.

Double click once more on the layer with graphics, and the box "Layer Properties" appears.

In the left panel choose "Style".

Choose "Categorized" (see the picture above)

Under "Column" we choose the column in the database table, which we want to group by. In our example we choose "Kommunur_hagtol_ibugvar".

Choose a "Color ramp" by your own choice.

Click on "Classify".

Click on "Apply" and "OK".



Now we have a map, which is grouped by population number, and has got colors by this grouping.

"Joins" made it possible to group by a column, which is not in the same layer as the map.


You are welcome to write comments below. If you have any questions, please post in the forum.