'How can i use/send the information inside an array from one block to another block js

So my issue is this I have a SQL query that push its result into an array

connection.query('SELECT id FROM parada WHERE ubi_calle_id =? ',[calleID], async (err,resultid)=>{

            for (i =0; i < resultid.length; i++){
                ParIds[ParIds.length] = {
                  id: resultid[i].id  
                }           
            }
            
            for(i=0; i < ParIds.length; i++){
                parID =  ParIds[i].id
                
                //console.log(parID, "par id")
                
                connection.query(`SELECT parada.id , trayecto.recorrido_id, recorrido.linea_id, lineas.name AS nombre_linea, lineas.ramal FROM (((parada INNER JOIN trayecto ON parada.id= trayecto.parada_id) INNER JOIN recorrido ON trayecto.recorrido_id = recorrido.id)INNER JOIN lineas ON recorrido.linea_id= lineas.id) WHERE parada.id = ${parID} `, async (err,resultLineas)=>{
                    if (err) throw err;
                    
                    //console.table(resultLineas)
                    lineas.push(resultLineas);
                    console.log(lineas, "esto")
                    
        
                });
                
                
            } 
        })

So each element of the array lineas is an array of the result of the second query and it show something like this lineas = [[1,2,3],[1,4],[3]]

But now I have another SQL query that brigs me another result

connection.query('SELECT parada.*, calle.name AS ubi1, c.name as ubi2 FROM ((parada INNER JOIN calle ON parada.ubi_calle_id = calle.id)INNER JOIN calle c ON parada.ubi_casi = c.id) WHERE ubi_calle_id =? ',[calleID], async (err,result)=>{ });
      

Inside of this second SQL query "block" I need to use or somehow bring the array "lineas" that I got from the first SQL query but I can't do it, If I try to use it inside the second SQL query the array is always empty "console.log (lineas) will show []. So how can I save that array from the first SQL query in way where console.log(lineas) inside the second SQL query will also bring me lineas= [[1,2,3],[1,4],[3]]

PS : I'm so sorry for my bad english I tried my best. PS2 : The only way I can somehow use the data from lineas inside the second SQL query is if I put the second SQL query inside the first 1 which is not an option since it will be inside the for loop.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source