In ADF, currently, self-referencing variables is not supported, that is the reason why the temp_arr variable was used.
UPDATE:
Your activities are running parallelly inside For-Each. You need to check the Sequential check box in the For-Each activity to run the activities sequentially.

The output array will be stored in the res_arr variable. If you want to access the array after For-Each, you need to use this array.
My pipeline JSON for your reference:
Change the datasets name and query and activity names as per your requirement and use it.
{ "name": "lookup concat pipeline", "properties": { "activities": [ { "name": "Lookup1", "type": "Lookup", "dependsOn": [], "policy": { "timeout": "0.12:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "source": { "type": "AzureSqlSource", "sqlReaderQuery": "SELECT COUNT(*) as TotalCount FROM lookup1", "queryTimeout": "02:00:00", "partitionOption": "None" }, "dataset": { "referenceName": "lookup_table", "type": "DatasetReference" }, "firstRowOnly": true } }, { "name": "ForEach1", "type": "ForEach", "dependsOn": [ { "activity": "Lookup1", "dependencyConditions": [ "Succeeded" ] } ], "userProperties": [], "typeProperties": { "items": { "value": "@range(0, add(div(activity('Lookup1').output.firstRow.TotalCount, 4), 1))", "type": "Expression" }, "isSequential": true, "activities": [ { "name": "Lookup2", "type": "Lookup", "dependsOn": [], "policy": { "timeout": "0.12:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "source": { "type": "AzureSqlSource", "sqlReaderQuery": { "value": "SELECT * FROM lookup1 ORDER BY id OFFSET @{mul(int(item()), 4)} ROWS FETCH NEXT 4 ROWS ONLY", "type": "Expression" }, "queryTimeout": "02:00:00", "partitionOption": "None" }, "dataset": { "referenceName": "lookup_table", "type": "DatasetReference" }, "firstRowOnly": false } }, { "name": "temp_arr", "type": "SetVariable", "dependsOn": [ { "activity": "Lookup2", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "temp_arr", "value": { "value": "@variables('res_arr')", "type": "Expression" } } }, { "name": "union temp and and lookup array", "type": "SetVariable", "dependsOn": [ { "activity": "temp_arr", "dependencyConditions": [ "Succeeded" ] } ], "policy": { "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "variableName": "res_arr", "value": { "value": "@union(variables('temp_arr'),activity('Lookup2').output.value)", "type": "Expression" } } } ] } } ], "variables": { "temp_arr": { "type": "Array" }, "res_arr": { "type": "Array" } }, "annotations": [], "lastPublishTime": "2024-05-29T04:16:16Z" }, "type": "Microsoft.DataFactory/factories/pipelines" } 


