How to create a union of two views? I'm trying to get a union of a user's nodes and comments sorted by "post date".
This post links to sandbox projects for D6 but there is nothing for 7.

This post has an example of using hook_views_pre_execute() and a SQL UNION in D6. This doesn't work for D7 with views 3.

I came across merlinofchaos' comment 


  Because we're now using Drupal's new query generator, the query is a SelectQuery object which you will have to modify or replace. Look up Drupal 7's new database layer for more information.


Does anyone have an example of how to do this or any other solution to combine two views?
Here's a working and tested example:

/**
 * Implements hook_views_pre_execute().
 */
function mymodule_views_pre_execute(view &amp;$view) {
  if ($view-&gt;name == 'my_view') {
    $query1 = &amp;$view-&gt;build_info['query'];

    // Basic setup of the second query.
    $query2 = db_select('another_table', 'at')
      -&gt;condition('some_field', 0, '&gt;')
      -&gt;condition('some_other_field', 12345);

    // The number of fields (and their aliases) must match query1.
    // Get the details with:
    // dpm($query1-&gt;getFields());
    $query2-&gt;addField('at', 'some_field', 'alias1');
    $query2-&gt;addField('at', 'some_other_field', 'alias2');
    $query2-&gt;addField('at', 'some_other_field2', 'alias3');
    $query2-&gt;addField('at', 'some_other_field3', 'alias4');

    // Verify that queries are very similar.
    // dpq($query1);
    // dpq($query2);

    // Matrimony.
    $query1 = $query2-&gt;union($query1, 'UNION ALL');

    // Manual test.
    // dpm($query1-&gt;execute()-&gt;fetchAll());

  }
}


This works for most views.  However some style plugins may do fancy stuff that won't work with this technique (Calendar module I'm looking at you).