--- database.mysql.inc  (revision 3207)
+++ database.mysql.inc  (working copy)
@@ -363,7 +363,7 @@
 function db_distinct_field($table, $field, $query) {
   $field_to_select = 'DISTINCT('. $table .'.'. $field .')';
   $matches = array();
-  if (preg_match('/^SELECT(.*?)FROM(.*)/is', $query, $matches)) {
+  if (preg_match('/^SELECT(.*?)\<FROM\>(.*)/is', $query, $matches)) {
     $select = preg_replace(
       '/((?:^|,)\s*)(?<!DISTINCT\()(?:'. $table .'\.)?'. $field .'(\s*(?:,|$))/is',
       '\1'. $field_to_select .'\2', $matches[1], 1
