Knex从多个表中选择

3

我想用knex来运行以下SQL:

select * from (
  (select * from foo)
  union all
  (select * from bar)) as biz limit 10 offset 20;

有没有一种不使用 knex.raw 的方法来实现这个功能?
1个回答

5

Knex支持使用unionunionAll。这已经在文档中有所说明。

knex.select().from(function() {
    this.select().from('foo')
        .unionAll(function() {
            this.select().from('bar')
        }).as('biz')
}).limit(10).offset(20).toString()

输出:

select * from (select * from `foo` union all select * from `bar`) as `biz` limit 10 offset 20

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接