title: get the last insert id in node.js and pass it to a second query
body: <p>I have in my sql database 2 tables, a table called club and a table called players, they are connected by one to many relationships, the query in node.js works fine but i can not get the last insert of table club , i need to it for insert in the foreign key in the table players</p>
  <pre><code>here what i have tried in node.js:
  
  
  
         module.exports={
   create:(data,callback)=&gt;{
    var myArray = new Array();
   /* for(let item of data.players) {
      console.log(item.firstname);
  }*/
  
  data.players.forEach((player) =&gt; {
    console.log(player.id);
    console.log(player);
    var playerModel ={
      id : player.id,
      firstname : player.firstname,
      lastname : player.lastname,
      position : player.position,
      price : player.price,
      appearences : player.appearences,
      goals : player.goals,
      assists : player.assists,
      cleansheets : player.cleansheets,
      redcards : player.redcards,
      yellowcards : player.yellowcards,
      image : player.image,
      clubid : player.clubid,
    };
    console.log(&quot;model&quot;+playerModel.position);
    myArray.push(playerModel);
  });
  var id;
   
   pool.query(
        'insert into club(userid,name,price) values(?,?,?)',
     [
          data.userid,
          data.name,
          data.price
        ],
      
        (error,result) =&gt; {
          if(error){
            callback(error);
           
          }
       /*   id = result.insertId;
          console.error(result);
          console.log(result+&quot;  result&quot;);*/
          
          console.log(result.insertId);
          return callback(null,result.insertId);
        },
  
        
      );
  
  
  
      for(var item of myArray){
      pool.query(
        
        'insert into players(id,firstname,lastname,position,price,appearences,goals,assists,cleansheets,redcards,yellowcards,image,clubid) values (?,?,?,?,?,?,?,?,?,?,?,?,?)',
         [ 
         item.id,
         item.firstname,
         item.lastname,
         item.position,
         item.price,
         item.appearences,
         item.goals,
         item.assists,
         item.cleansheets,
         item.redcards,
         item.yellowcards,
         item.image,
         (
          'select top 1 id from club order by id desc'
          )
         ],
        
   
       (error,results,fields)=&gt;{
         if(error){
           callback(error);
         }
         return callback(null,results);
       },
      );
      }
    },
       
  </code></pre>
  <p>no idea about how to do this</p>