node.js and mysql - need data from select to update

my problem is that i try to write a callback method in node.js for different mysql selects and updates. The update commands must wait for the data from the select to work with it. but sometimes they cant, cause the vars are "undefined". maybe i need a callback function to make that work. In the following example there is a jQuery animation to wait for before the callback starts. But how can i solve that with an mysql command:

function mySandwich(param1, param2, callback) {  
        alert('Started eating my sandwich.\n\nIt has: ' + param1 + ', ' + param2);  

        $('#sandwich').animate({  
            opacity: 0  
        }, 5000, function() {  
            // Animation complete. 
            if (callback && typeof(callback) === "function") {  
            callback();  
        }   
        });  

    }  

    mySandwich('ham', 'cheese', function() {   
        alert('Finished eating my sandwich.');  
    });  

I hope someone can explain me that. Best regards

I would recommend looking at async.js it allows for things to run in series, or parallel, and pass information on to either a final callback function or to the next function.