I am trying to use the SQL Execute in the graph modeler, receiving as input the output of another algorithm. The problem is that I couldn't specify that the "input" in the FROM of the SQL Execute should be the "output" of the process prior to it. This makes batch execution impossible, as I can only execute by specifying in FROM, the name of a table that is already in canvas. It's curious because, although I'm working inside the modeler, with the execute SQL properly linked in the previous process, it insists on fetching the table in the canvas. Is there any way to specify in SQL to fetch from the previous table? Below, I share the query I am trying to execute and the image of the modeler:

SELECT *, MAX ("area_segm") as 'area_segm_'


GROUP BY "id_objeto"

Graphic Modeler

Important! When I run it for the first time, it results in the following message: Referenced table 27a_SUBOBJECTS_UTEIS in query not found!

When I run it again, it works because the 27a_SUBOBJETS_UTEIS layer has already been added to the canvas, and the Execute SQL algorithm looks there.

I already tried it the way below, but it didn't work either.

SELECT *, MAX ("area_segm") as 'area_segm_'

FROM "output"

GROUP BY "object_id"

I just have to figure out what I should write after FROM, to get the result of the algorithm 27a from my model as input.


2 Answers 2


The solution is described in the QGIS guide at this link, in short you have to use

FROM input1


If the query you included in the question is the only thing to calculate, you could take a look at the Statistics by categories tool, which can also calculate a max value with a group field.

Still the solution for using a model output in a sql query would be interesting for other purposes.

  • 1
    Thanks for the help, I didn't know this algorithm yet. I think it will be very useful, but it only generates the table, it doesn't generate a new vector bringing only the ones with the largest areas within each object. By including FROM "input1" as indicated by MrXsquared, the expression worked perfectly. But thanks again for your tip. Mar 17 at 1:47

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.