diff --git a/core/lib/Drupal/Core/Database/Query/Condition.php b/core/lib/Drupal/Core/Database/Query/Condition.php
index 4bb1d09..585bf76 100644
--- a/core/lib/Drupal/Core/Database/Query/Condition.php
+++ b/core/lib/Drupal/Core/Database/Query/Condition.php
@@ -196,6 +196,7 @@ public function compile(Connection $connection, PlaceholderInterface $queryPlace
 
             $placeholders = array();
             if ($condition['value'] instanceof SelectInterface) {
+              $this->ensureBrackets($operator);
               $condition['value']->compile($connection, $queryPlaceholder);
               $placeholders[] = (string) $condition['value'];
               $arguments += $condition['value']->arguments();
@@ -318,6 +319,25 @@ protected function mapConditionOperator($operator) {
   }
 
   /**
+   * Ensures that the value being tested against is bracketed.
+   *
+   * Some operators don't usually need brackets around the value being tested,
+   * but when the value being tested is a SelectQueryInterface it needs to be
+   * bracketed.  This function adds those necessary brackets.
+   *
+   * @param array $operator
+   *   The extra handling directives for the operator
+   */
+  private function ensureBrackets(&$operator) {
+    if (strpos($operator['prefix'], '(') === FALSE) {
+      $operator['prefix'] .= ' (';
+    }
+    if (strpos($operator['postfix'], ')') === FALSE) {
+      $operator['postfix'] = ')' . $operator['postfix'];
+    }
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function conditionGroupFactory($conjunction = 'AND') {
diff --git a/core/modules/system/src/Tests/Database/SelectSubqueryTest.php b/core/modules/system/src/Tests/Database/SelectSubqueryTest.php
index 9eb3048..c4c12c1 100644
--- a/core/modules/system/src/Tests/Database/SelectSubqueryTest.php
+++ b/core/modules/system/src/Tests/Database/SelectSubqueryTest.php
@@ -95,6 +95,19 @@ function testConditionSubquerySelect() {
     // WHERE tt2.pid IN (SELECT tt.pid AS pid FROM test_task tt WHERE tt.priority=1)
     $people = $select->execute()->fetchCol();
     $this->assertEqual(count($people), 5, 'Returned the correct number of rows.');
+
+    // Create a subquery, which only returns one value
+    $subquery2 = db_select('test_task', 'tt');
+    $subquery2->addField('tt', 'priority');
+    $subquery2->condition('tt.task', 'eat'); // Gives 3
+
+    // Create another query that tests against the value returned by the subquery
+    $select2 = db_select('test_task', 'tt2');
+    $select2->addField('tt2', 'task');
+    $select2->condition('tt2.priority', $subquery2, '<');
+
+    $tasks = $select2->execute()->fetchCol();
+    $this->assertEqual(count($tasks), 4, 'Returned the correct number of rows.');
   }
 
   /**
