title: How to generate a USING clause in JOIN queries with Laravel's Query Builder?
body: <p>PostgreSQL supports <a href="http://www.postgresql.org/docs/9.4/static/queries-table-expressions.html" rel="nofollow noreferrer">USING</a> clauses in JOIN statements, and I want to use it to simplify my query. For example:</p>
  
  <pre><code> select * from a join b using (x, y, z) where ... order by x;
  </code></pre>
  
  <p>How do I express this with Laravel's Query Builder or Eloquent?</p>
  
  <pre><code>DB::table('a')
      -&gt;select('*')
      -&gt;join('b', function($join))
      -&gt;where(...)
      -&gt;orderBy('x');
  </code></pre>
  
  <p>Note that this question is different from <a href="https://stackoverflow.com/questions/31465918/how-to-generate-a-natural-join-query-with-laravels-query-builder">https://stackoverflow.com/questions/31465918/how-to-generate-a-natural-join-query-with-laravels-query-builder</a> where I was asking about NATURAL JOIN, not JOIN USING.</p>
  
  <p>Also, I'm aware that I can have almost the same effect with multiple <code>$join-&gt;on(...)</code> statements, but then I have duplicate columns and must always qualify columns that are in both <code>a</code> and <code>b</code>. That is, I'd have to write <code>'a.x'</code> instead of <code>'x'</code> even though it doesn't matter, because the join query ensures that both are equal anyway. The USING clause solves this problem neatly, by generating only a single result column <code>x</code>, knowing there is only this one value.</p>