Problem joining multiple matching rows from non-geometry CSV file

attribute-joinscsvqgis

I am using QGIS 3.24.0. I have a shapefile, called "Map_CorrectionDEF, in which one of the fields is "unitcode". On the other hand, I have a CSV file, called crop_main (no geometry), in which one of the fields is "unitcode". I would like to merge them through the field "unitcode".

I do the following:

enter image description here

However, in my CSV file, there is a variable in which I am interested which is called "cropclass". This variable takes different values within the values of variable "unitcode". For example, for "unitcode" = 12000, it takes values 7 and 16. But when I do the merge, the final output only merge the values when it takes 16. I am not understanding why. This happens several times. It just an example that I show now with picture:

CSV file:

enter image description here

Final output in the Attribute table of my shapefile after doing the join:

enter image description here

[I edit to make clear what is the goal and make it clear why join does not work]

The values from variable "unitcode" in my shape file appears several times. It's a grid cell and the "unitcode" says the country in which the cell belongs. So, all the cells in the same country has the same value of "unitcode". For each cell, which has an associated value of "unitcode", I would like to join every value of my csv file which has the value of "unitcode". More specific, if cell 1 which has a value of "unitcode" 12000, I would like to join all the observations which appears in my csv value where the "unitcode" is equal to 12000.

Best Answer

QGIS joins are either 1:1 or Many:1. Your join table contains more than one mapping from unitcode=12000 to cropclass but only one of those will be picked up in a join. See https://psqgis.org/joins.html. Perhaps you need to use a relate, discussed at the same link, but that depends on your application.

Related Question