[英]how can i use an array of values inside where clause in knex?
我如何使用一個值數組在where子句中進行比較,如下面的代碼所示,“ frompersons”是一個名稱數組,是第一個調用的響應,因此我想從“ chatterusers”數據庫中獲取其信息。 但是,如何在下一個where子句中使用此數組?
return knex('frndrqst').where({ toperson: toperson })
.select('fromperson')
.then(frompersons => {
db.select('*').from('chatterusers')
.where( 'name', '=', frompersons )
.then(data => {
res.json(data);
})
.catch(err => res.json("Unable to load frndrqsts !!!"))
})
.catch(err => res.json("Unable to load frndrqsts !!!"))
//get the list of name from 'formperson' table
var subquery = knex.select('name').from('fromperson');
//get in all information from 'chatterusers table' that name is equal with name
return knex.select('*').from('chatterusers')
.whereIn('name', subquery)
輸出:
select * from chatterusers where name in (select name from fromperson)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.