4

I have an attribute table named 'data.shp' and a vector layer 'pop.shp'.

The 'data.shp' has the following fields "ID", "value1", "value2"

The 'pop.shp' has the "ID" field (same with the 'data.shp')

I want to update 'pop.shp' and add the fields "value1", "value2" from 'data.shp' where "ID" (from 'data.shp') is equal to "ID" (from 'pop.shp').

How could I do that in QGIS?

Taras
  • 32,823
  • 4
  • 66
  • 137
Nat
  • 219
  • 2
  • 8

2 Answers2

8

QGIS has built-in table join capabilities. If you want to add fields from a table (data.shp) into another layer (pop.shp), then go this way:

  • Right click on pop.shp -> Properties -> Joins -> "+"
  • Choose relevant layer and key field for the join
  • Check which fields you want to add
  • Click OK

The attribute table from your pop.shp layer should now include the data you need. To make this permanent, save the layer as a new file.

enter image description here

Gabriel
  • 3,136
  • 13
  • 33
Christophe P.
  • 2,175
  • 11
  • 22
4

Another solution implies the usage of a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer....

With the following query, it is possible to update 'pop.shp' and add the fields "value1", "value2" from 'data.shp'.

SELECT
    pop.*,
    data.value1,
    data.value2
FROM
    "pop"
LEFT JOIN "data"
    ON pop.id = data.id

References:

Taras
  • 32,823
  • 4
  • 66
  • 137