diff --git includes/database/query.inc includes/database/query.inc
index 2e775be..de09610 100644
--- includes/database/query.inc
+++ includes/database/query.inc
@@ -779,45 +779,47 @@ class MergeQuery extends Query {
       $select->condition($field, $value);
     }
 
-    $select = $select->countQuery();
-    $sql = (string) $select;
+    // Using SELECT FOR UPDATE syntax will lock the rows we want to attempt to update.
+    $sql = ((string) $select) . ' FOR UPDATE';
     $arguments = $select->getArguments();
-    $num_existing = $this->connection->query($sql, $arguments)->fetchField();
 
-
-    if ($num_existing) {
-      // If there is already an existing record, run an update query.
-
-      if ($this->updateFields) {
-        $update_fields = $this->updateFields;
-      }
-      else {
-        $update_fields = $this->insertFields;
-        // If there are no exclude fields, this is a no-op.
-        foreach ($this->excludeFields as $exclude_field) {
-          unset($update_fields[$exclude_field]);
+    try {
+      // If there are already existing records, run an update query.
+      if ($this->connection->query($sql, $arguments)->fetch()) {
+        if ($this->updateFields) {
+          $update_fields = $this->updateFields;
         }
-      }
-      if ($update_fields || $this->expressionFields) {
-        // Only run the update if there are no fields or expressions to update.
-        $update = $this->connection->update($this->table, $this->queryOptions)->fields($update_fields);
-        foreach ($this->keyFields as $field => $value) {
-          $update->condition($field, $value);
+        else {
+          $update_fields = $this->insertFields;
+          // If there are no exclude fields, this is a no-op.
+          foreach ($this->excludeFields as $exclude_field) {
+            unset($update_fields[$exclude_field]);
+          }
         }
-        foreach ($this->expressionFields as $field => $expression) {
-          $update->expression($field, $expression['expression'], $expression['arguments']);
+        if ($update_fields || $this->expressionFields) {
+          // Only run the update if there are no fields or expressions to update.
+          $update = $this->connection->update($this->table, $this->queryOptions)->fields($update_fields);
+          foreach ($this->keyFields as $field => $value) {
+            $update->condition($field, $value);
+          }
+          foreach ($this->expressionFields as $field => $expression) {
+            $update->expression($field, $expression['expression'], $expression['arguments']);
+          }
+          $update->execute();
+          return MergeQuery::STATUS_UPDATE;
         }
-        $update->execute();
-        return MergeQuery::STATUS_UPDATE;
+      }
+      else {
+        // If there is no existing record, run an insert query.
+        $insert_fields = $this->insertFields + $this->keyFields;
+        $this->connection->insert($this->table, $this->queryOptions)->fields($insert_fields)->execute();
+        return MergeQuery::STATUS_INSERT;
       }
     }
-    else {
-      // If there is no existing record, run an insert query.
-      $insert_fields = $this->insertFields + $this->keyFields;
-      $this->connection->insert($this->table, $this->queryOptions)->fields($insert_fields)->execute();
-      return MergeQuery::STATUS_INSERT;
+    catch (Exception $e) {
+      $transaction->rollback();
+      return FALSE;
     }
-
     // Transaction commits here where $transaction looses scope.
   }
 
