I'm trying to code a function that does two queries and I wish to have access to both record sets in the final code-block; my code looks similar to:
295 connection.query(sql1, function selectDb(err, results, fields) {
296 if (err) {
297 throw err;
298 }
299
300 result = results[0];
301 console.log(result);
302
303 console.log(sql2);
304 connection.query(sql2, function selectDb(err, results, fields) {
305 if (err) {
306 throw err;
307 }
309 console.log(result);
problem is the var result retains the first record set until after the second query @304 and displays 'undefined' @309 (had the record set in previous displays).
I don't know how to pass the first record set value to the inner code async code block @304; Tried to add result as a parameter;
304 connection.query(sql2, function selectDb(err, results, fields, result) {
result still undefined @309
Help appreciated.