QueryDSL - add subquery into FROM statement

廉价感情. 提交于 2019-12-19 09:50:11

问题


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)?


回答1:


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);


来源:https://stackoverflow.com/questions/15020049/querydsl-add-subquery-into-from-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!