Mysql
 sql >> Database >  >> RDS >> Mysql

Più query in un'unica API

Il tuo codice dovrebbe essere così.

app.get('/api/task_details',function(req,res,err){
    var sql = "select * from users inner join user_level_task on users.user_id=user_level_task.user_id inner join tasks on tasks.task_id = user_level_task.task_id where task_name = 'game'";
    var sql2="select * from tasks where task_name='game'";
    var res1 = {}
    db.select(sql,function(err,data1){
        db.select(sql2,function(err,data2){
        res1.data1= data1;
        res1.data2=data2;
        res.end(JSON.stringify(res1));
    })
    })

})