【问题标题】:Use alias for JOIN using JOOQ's SelectQuery使用 JOOQ 的 SelectQuery 为 JOIN 使用别名
【发布时间】:2015-05-05 13:52:05
【问题描述】:

我需要使用 JOOQ 的 SelectQuery 编写带有嵌套选择和连接的查询:

    SELECT *
    FROM (select * from 
    "public"."parent" 
    order by "public"."parent"."setup_time" 
    desc limit 10 offset 0) as "parent1" 
    join "public"."child" 
    on "public"."child"."parent_id" = "parent1"."id" 
    where "public"."child"."name" = 'test'

所以,我写了这样的东西:

SelectQuery<ParentRecord> subSelectQuery = context.selectQuery(PARENT);
selectQuery.addJoinOnKey(CHILD, JoinType.JOIN, CHILD.PARENT_ID);

但它会生成类似的sql代码

join "public"."child" on "public"."child"."parent_id" =  "public"."parent"."id

如何使用别名 parent1 而不是完整的表名 "public"."child"."parent_id"

【问题讨论】:

    标签: sql join alias jooq


    【解决方案1】:

    我找到了解决办法。

    SelectQuery<ParentRecord> selectQuery = context.selectQuery(subSelectQuery.asTable(PARENT.getName()));
    selectQuery.addJoin(CHILD, JoinType.JOIN, CHILD.PARENT_ID.eq(PARENT.as(PARENT.getName()).ID));
    

    【讨论】:

      猜你喜欢
      • 2013-11-19
      • 2021-04-30
      • 1970-01-01
      • 2012-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      相关资源
      最近更新 更多