Table<Record> out = A.join(B)
.on(A.ID.eq(B.OID))
.and(A.WORD.eq(B.NEW_WORD)).asTable("out");
Table<Record> in = A.join(B)
.on(A.ID.eq(B.OID))
.and(A.WORD.eq(B.NEW_WORD)).asTable("in");
Condition inCondition = in.getField(A.ADJECTIVE).eq(adj)
.and(in.getField(A.WORD).in(listofwords))
.and(in.getField(A.VERB).notIn(listofverbs));
.and(in.getField(
B.ID).lessOrEqual(id));
Table<Record> nested = factory.select(
out.getField(A.WORD),
out.getField(A.VERB),
out.getField(B.TIME))
.from(out)
.where(out.getField(
B.ID)
.eq(factory.select(max(in.getField(
B.ID)))
.from(in)
.where(inCondition)
.and(out.getField(A.VERB)
.eq(in.getField(A.VERB)))
.groupBy(in.getField(A.VERB)))
).asTable("nested");
Result<Record> records = factory.select(nested.getFields())
.from(nested)
.orderBy(nested.getField(
B.ID).desc())
I believe the error comes from doing out.getField(
A.ID) and in.getField(
B.ID) which both get aliased as
nested.id
I'm not sure how I can alias one of the ID fields, eg.
B.ID so that I can reference them separately in the select for the nested table.
A.ID and
B.ID do not have any relationships together