How use select query for 2 different tables based on the data

by Manasa   Last Updated August 17, 2018 11:06 AM

array.map(function(t){
var table_name = t.user_id == null/undefined ? "university" : "users";
                        var table_field = v.user_id == null/undefined ? "university_id" : "user_id ";
                        db.query('SELECT * from ' + table_name+ ' where table_field = $1', [u._id], function(err, result) {
    return result.rows
                        })
})

if user id is present in array then the code should take table name as users and user_id as table_field, if the user_id is not present then it should take university as table name and university_id as table_field. someone please guide me on this.



Related Questions


Postgres gist slow index f_unaccent

Updated April 09, 2018 20:06 PM