Hi,
I'm trying to produce a dynamic self join on table that I haven't generated
any code artifacts for. At run time I'd like to create this query
select * from some_table as a join sometable as b on a.id = b.id and a.id>=
b.id
whereby the table name and the columns to join on are supplied by dynamic
configuration.
I've tried to sketch out the following, but I think my understanding of the
API lacks somewhat:
Factory db = new Factory(SQLDialect.HSQLDB);
Table<Record> table = tableByName("PUBLIC", "SOME_TABLE");
Table<Record> a = table.as("a");
Table<Record> b = table.as("b");
Field<Integer> id = fieldByName(Integer.class, "PUBLIC", "SOME_TABLE",
"ID");
db.select().
from(a).
join(b).
on(id.eq(field)).
and(id.ge(field));
Is there a way to programmatically scope the id field on a and b in order
to produce the join?
Cheers,
Ben