One way is to use virtual layers (thank you @johns):
- Layer/Create Layer/New Virtual Layer
- Import the layers you want to join
- Write SQL script, then test, then click "add". Please note that it seems SQL doesn't support layers with spaces, so if you have "layer 1" rename or export to a new layer "layer_1" first. You can also replace an attribute name in SELECT by * to select all attributes, for instance JoinLayerName.*
SQL script is (at least it worked for me):
SELECT JoinLayerName.joinlayerattribute1, TargetLayerName.targetlayerattribute1
FROM JoinLayerName
JOIN TargetLayerName
WHERE JoinLayerName.joiningattributefield = TargetLayerName.joiningattributefield
JoinLayerName.joinlayerattribute1, TargetLayerName.targetlayerattribute1
are the attributes from both layers you want to display in the virtual layer)
You can then export the virtual layer to a new geopackage or shapefile, the only thing is that I could georeference the file but I was not able to see it (it was invisible, the polygons from the original file don't seem to be there). I am unsure how you could keep the geometry as well, I have to investigate this more (unless someone knows how to do it).