xxx.jooq.internal.tables.Command cmd = COMMAND.as( "cmd" );
xxx.jooq.internal.tables.Command aliasedCmd = COMMAND.as( "aliasedCmd" );
CommonTableExpression<Record2<String,String>> getCommand = name("getCommand")
.fields("id","parent_id")
.as(create
.select(cmd.ID, cmd.PARENT_ID)
.from(cmd)
.where(cmd.ID.eq("some_val"))
.union(create
.select(aliasedCmd.ID, aliasedCmd.PARENT_ID)
.from(aliasedCmd)
.where(aliasedCmd.ID.eq(cmd.PARENT_ID))));
Result<?> obj = create.with(getCommand).select().fetch();
==========
The run time error message
org.jooq.exception.DataAccessException: SQL [with "getCommand"("id", "parent_id") as ((select "cmd"."id", "cmd"."parent_id" from "internal"."command" as "cmd" where "cmd"."id" = ?) union (select "aliasedCmd"."id", "aliasedCmd"."parent_id" from "internal"."command" as "aliasedCmd" where "aliasedCmd"."id" = "cmd"."parent_id")) select 1]; ERROR: missing FROM-clause entry for table "cmd"
Position: 264
Thanks,
Amit.