Hi Stefan,

Just alias your tables, like in SQL:
https://www.jooq.org/doc/latest/manual/sql-building/table-expressions/aliased-tables/aliased-generated-tables/

I hope this helps,
Lukas

On Tue, Sep 19, 2023 at 5:00 PM Stefan Sator <[email protected]>
wrote:

> Hello everyone,
>
> I want to join twice between a project table and a user table.
>
> Users can be attached to a project in the role as project leader or deputy.
>
> So far I tried(and different versions):
> var p = ProjectdbProject.PROJECTDB_PROJECT;
> var pl = SecuritydbUser.SECURITYDB_USER;
>
> int i = dbcontext.fetchCount(DSL.selectDistinct(p.ID)
> .from(p)
> .join(pl).on(p.FK_PROJECT_LEADER.eq(pl.ID))
> .join(pl).on(p.FK_DEPUTY.eq(pl.ID))
> .where(condition)
> .groupBy(p.ID));
>
> but the result was always this exception:
> Caused by: org.postgresql.util.PSQLException: ERROR: table name
> "securitydb_user" specified more than once
> at
> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2713)
> ~[postgresql-42.6.0.jar:42.6.0]
> at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2401)
> ~[postgresql-42.6.0.jar:42.6.0]
>
> Any ideas?
> Thanks alot!
>
> I search in the master class book but could not find any example covering
> joining the same table twice.
>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jooq-user/62d9594b-4c62-48ed-a29d-a07bb89f8d20n%40googlegroups.com
> <https://groups.google.com/d/msgid/jooq-user/62d9594b-4c62-48ed-a29d-a07bb89f8d20n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/CAB4ELO5K4ULWYnJwBKtQVa%2Bs8NV_UPH35Nesu8Xz%3DG%3Dhq4pPLw%40mail.gmail.com.

Reply via email to