title: Query wrap in Knex.js
body: <p>How do we wrap queries into groups on union?</p>
  
  <p>I have this query:</p>
  
  <pre><code>    SELECT * FROM (
         (SELECT u1.* FROM `user` AS u1 WHERE user_email IS NOT NULL GROUP BY u1.key)
         UNION ALL
         (SELECT u2.* FROM `user` AS u2 WHERE user_email IS NULL)
  ) AS u ORDER BY u.id LIMIT 10
  </code></pre>
  
  <p>I was only able to do up to this:</p>
  
  <pre><code>knex.select('*').from('user').whereNotNull('email').groupBy('user.key')
  .unionAll(function() {
    this.select('*').from('user as u2').whereNull('u2.email');
  }, true)
  </code></pre>
  
  <p>But this would result to:</p>
  
  <pre><code>SELECT user.* FROM `user` WHERE user.email IS NOT NULL
  UNION ALL
  (SELECT u2.* FROM `user` AS u2 WHERE email IS NULL)
  GROUP BY user.key
  </code></pre>
  
  <p>which is a fail. Is there a way to do this? I need something like the first query because I need to retrieve sorted by id and paginated.</p>