The SQL USING and jOOQ onKey() shortcuts
So far, we've covered the typical JOIN
s that are commonly used in daily work. Before we continue with more types of JOIN
s, let's introduce two convenient shortcuts that are useful for expressing more concise JOIN
s.
SQL JOIN … USING
In certain cases, the SQL JOIN … USING
clause can be a convenient alternative to the classical JOIN … ON
clause. Instead of specifying a condition in the JOIN … ON
clause, we enlist the JOIN … USING
clause in the set of fields (columns) whose names are common to both tables – the left-hand side table and right-hand side table of a JOIN
operation. In jOOQ, the USING
clause is rendered via the using()
method, as shown in the following example. The EMPLOYEE_NUMBER
column mentioned in using()
is the primary key of the EMPLOYEE
table and the foreign key of the SALE
table:
ctx.select(EMPLOYEE.FIRST_NAME, EMPLOYEE.LAST_NAME, ...