3

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 QueryDSL (I am not using JPA and JDO - only clean sql)?

Brantner
  • 105
  • 1
  • 2
  • 8

1 Answers1

3

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);
Timo Westkämper
  • 21,824
  • 5
  • 78
  • 111