how to join with mysql + nodejs

0

I did this function to join between 2 tables but I think that is not the right way

function insertarDatosToArchivos(){

objBD.query('SELECT ID_U from usuario', function(err, rows, fields) {
    for (var i = 0; i < rows.length; i++) {
        objBD.query('SELECT ID_L   from LETRA where rows[i].ID_U=LETRA.ID_U', function(err, rows, fields) {

        });
    };

});

};
    
asked by hubman 02.10.2016 в 04:01
source

1 answer

1

I think it's simpler if you do the query in a single call to mysql . Something like this:

function insertarDatosToArchivos(){

    objBD.query('SELECT u.ID_U, l.ID_L from usuario u INNER JOIN LETRA l ON u.ID_U = l.ID_U', function(err, rows, fields) {
        //Tu código de lógica acá
    }});

};

In this way you optimize the number of calls to the database and in turn the execution time of your function.

    
answered by 02.10.2016 / 05:18
source