title: QueryDSL - how to join to a union of subqueries
body: <p>I'm building a SQL query with QueryDSL that contains several subqueries joined in a union. This is the base of my query:</p>
  
  <pre><code>QTransaction t = QTransaction.transaction;
  query = query.from(t).where(t.total.gt(BigDecimal.ZERO));
  </code></pre>
  
  <p>I then have several subqueries to obtain client names associated with a transaction. I've cut down to two for the example:</p>
  
  <pre><code>SQLSubQuery subQuery = new SQLSubQuery();
  subQuery = subQuery.from(t).join(t.fk462bdfe3e03a52d4, QClient.client);
  ListSubQuery clientByPaid = subQuery.list(t.id, bt.paidId, QClient.client.name.as("clientname"));
  
  subQuery = new SQLSubQuery();
  subQuery = subQuery.from(t).where(t.paidId.isNull(), t.clientname.isNotNull());
  ListSubQuery clientByName = subQuery.list(t.id, Expressions.constant(-1L), t.clientname.as("clientname"));
  </code></pre>
  
  <p>How do I union these together, and join the union with my main query? This is my current attempt:</p>
  
  <pre><code>subQuery = new SQLSubQuery();
  subQuery = subQuery.from(subQuery.unionAll(clientByPaid,clientByName).as("namequery"));
  
  
  query = query.leftJoin(subQuery.list(
              t.id, Expressions.path(Long.class, "clientid"),
                      Expressions.stringPath("clientname")),
                      Expressions.path(List.class, "namequery"));
  </code></pre>
  
  <p>This compiles, but generates invalid SQL at runtime when I attempt <code>query.count()</code>.  Likely mistakes:</p>
  
  <ul>
  <li>The syntax for the union of subqueries.</li>
  <li>The connection between the <code>.as(...)</code> expression that names the subquery result columns and the path expression used in the <code>leftJoin</code>.</li>
  </ul>