I am trying to use dbquery to get a value from a table when a record in it is the same as a value in the source table.

In the table where I need the value-added (Sewerage_Manholes...) I am trying



What am I not doing correctly?

I don't want to run a join by attribute in this case as if this works it opens up the opportunity to use complex SQL.

  • 1
    What field type is your column asset? I only see Asset_ID.
    – DirkB.
    Jul 22 '19 at 6:32
  • Both are integer. See the bottom table.
    – GeorgeC
    Jul 22 '19 at 6:47
  • 2
    Seems a typo in your second argument, commision_date against commission_date field.
    – Kazuhito
    Jul 22 '19 at 9:19
  • 2
    I see your point and your structure is correct. There is an open issue.
    – Kazuhito
    Jul 22 '19 at 11:22
  • 2
    Just a thought: if 'complex' + 'SQL' is what you are looking for, the doors are wide open already, albeit elsewhere, with a different workflow: move away from keeping files on disk updated to managing only base data within a QGIS Project, and create and manipulate analytics and derivates as Virtual Layers via the DB Manager; export to file only when needed. Virtual Layer definitions are saved into the QGIS project file.
    – geozelot
    Jul 22 '19 at 11:46

If dbquery won't work, this expression should (note the single and double quotes):


Be aware this will return NULL when there is no matching row in the 'asset' table and will overwrite an existing date. I would first select all the features where 'commission_date' is null and then check the box 'Only update x selected features' in the field calculator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.