QueryDSL - add subquery into FROM statement

后端 未结 1 1361
情书的邮戳
情书的邮戳 2021-01-14 12:47

I need to implement sql query like:

SELECT * FROM (SELECT a FROM b WHERE a.z = 1) WHERE rownum <=1;

How can I write such statement with

相关标签:
1条回答
  • 2021-01-14 13:43

    Querydsl SQL emulates paging of all the supports databases, so you can write directly

    query.from(a)
        .where(a.z.eq(1))
        .limit(1)
        .list(a);
    

    If you need to write this via a subquery then like this

    query.from(
      new SQLSubQuery().from(a).where(a.z.eq(1)).list(a).as(a))
     .where(rownum.loe(1))
     .list(a);
    
    0 讨论(0)
提交回复
热议问题