diff --git a/includes/handlers.inc b/includes/handlers.inc
index 2a33d5d..64a2ca1 100644
--- a/includes/handlers.inc
+++ b/includes/handlers.inc
@@ -1523,10 +1523,17 @@ class views_join {
    *   The source query, implementation of views_plugin_query.
    */
   function build_join($select_query, $table, $view_query) {
+    $table_data = views_fetch_data($this->table);
+
+    // 'table formula' overrides 'real table'
     if (empty($this->definition['table formula'])) {
-      $right_table = $this->table;
-    }
-    else {
+      if (!empty($table_data['table']['base']['real_table'])) {
+        $right_table = $table_data['table']['base']['real_table'];
+      }
+      if (empty($right_table)) {
+              $right_table = $this->table;
+      }
+    } else {
       $right_table = $this->definition['table formula'];
     }
 
@@ -1644,8 +1651,15 @@ class views_join_subquery extends views_join {
    *
    */
   function build_join($select_query, $table, $view_query) {
+    $table_data = views_fetch_data($this->table);
+
     if (empty($this->definition['table formula'])) {
-      $right_table = "{" . $this->table . "}";
+      if (!empty($table_data['table']['base']['real_table'])) {
+        $right_table = $table_data['table']['base']['real_table'];
+      }
+      if (empty($right_table)) {
+              $right_table = $this->table;
+      }
     }
     else {
       $right_table = $this->definition['table formula'];
diff --git a/includes/view.inc b/includes/view.inc
index d8c0c1f..cbfcc48 100644
--- a/includes/view.inc
+++ b/includes/view.inc
@@ -202,6 +202,13 @@ class view extends views_db_object {
   var $base_database = NULL;
 
   /**
+   * Tell Drupal the real name of the table. We can't always use the real table
+   * name if we're using multiple databases or tables, because some of them
+   * may collide in the global array that Views stores all the tables in.
+   */
+  var $real_table = NULL;
+
+  /**
    * Here comes a list of the possible handler which are active on this view.
    */
 
@@ -899,6 +906,10 @@ class view extends views_db_object {
       $this->base_database = $views_data['table']['base']['database'];
     }
 
+    if (!empty($views_data['table']['base']['real_table'])) {
+      $this->real_table = $views_data['table']['base']['real_table'];
+    }
+
     // Load the options.
     $query_options = $this->display_handler->get_option('query');
 
diff --git a/plugins/views_plugin_query_default.inc b/plugins/views_plugin_query_default.inc
index 030c5ea..fb1eae7 100644
--- a/plugins/views_plugin_query_default.inc
+++ b/plugins/views_plugin_query_default.inc
@@ -1290,8 +1290,14 @@ class views_plugin_query_default extends views_plugin_query {
 
     // Go ahead and build the query.
     // db_select doesn't support to specify the key, so use getConnection directly.
+    $table_prefix = '';
+    $real_table = $this->base_table;
+    if (isset($this->view->real_table)) {
+        $real_table = $this->view->real_table;
+    }
+
     $query = Database::getConnection($target, $key)
-      ->select($this->base_table, $this->base_table, $options)
+      ->select($real_table, $this->base_table, $options)
       ->addTag('views')
       ->addTag('views_' . $this->view->name);
 
