0
我是Node.js的新手。我正在使用Knex进行查询。我需要从两个不同的数据库中加入两张表。有谁能告诉我这是可能的吗?Knex从两个数据库中加入表格
knex.select('id', 'full_name','email', 'mobile_country_code', 'mobile', knex.raw('1 as active_status')).from('users').where(whereData).union(function() {
this.select('id','full_name', 'email', 'mobile_country_code', 'mobile', knex.raw('0 as active_status')).from('users_temp').where(whereData);
}).then(function(data) {
next(null, data);
}).catch(function(err) {
next(err.toString());
});
您可以加入普通SQL查询,你要创建的简单情况? –
( SELECT u1.id,u1.full_name,u1.email,u1.mobile_country_code,u1.mobile,1 AS active_status,u2.user_timeline_pic FROM db1.users AS u1 JOIN db2.users AS u2 ON u1.id = u2.id ) UNION( SELECT ID,FULL_NAME,电子邮件,mobile_country_code,移动,0 AS active_status, '默认/ user_profile_pic.png' AS user_timeline_pic FROM db1.users ) – Pillai
我需要的是上面给出。感谢您的回复@MikaelLepistö – Pillai