在javascript中不断收到此错误,错误:列引用"id"不明确



在这行SELECT po.*, du."displayName", du."email" FROM partner_orders as po, ds_user as du WHERE id = ${program.id}中,我一直得到错误列引用"id"是模棱两可的,我怎么解它?

async getAllParenFinanceOrders() {
const programOrders = await pool.query(
`SELECT po.*, du."displayName", du."email"
FROM partner_orders AS po 
LEFT JOIN ds_user AS du ON du.id = po."dsUserId" `

);

console.log("programOrders...", programOrders)
const partnerPrograms = await Promise.all(
programOrders.rows.map(async program => {
const query = await pool.query(
`SELECT po.*, du."displayName", du."email" FROM partner_orders as po, ds_user as du WHERE id = ${program.id}`
);
console.log('query.rows[0]...', query.rows[0])
return query.rows[0];
})
);
return {
programs: partnerPrograms

};
}

不确定这里需要的是哪个表id,但需要添加一个表id作为前缀:

SELECT po.*, du."displayName", du."email" FROM partner_orders as po, ds_user as du WHERE id = ${program.id}`
);

需要重写为

SELECT po.*, du."displayName", du."email" FROM partner_orders as po, ds_user as du WHERE po.id = ${program.id}`
);

SELECT po.*, du."displayName", du."email" FROM partner_orders as po, ds_user as du WHERE du.id = ${program.id}`
);

使错误消失。

相关内容

  • 没有找到相关文章

最新更新