Index: views_query.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/views_query.inc,v
retrieving revision 1.51.2.5
diff -u -r1.51.2.5 views_query.inc
--- views_query.inc	21 Jan 2007 23:17:38 -0000	1.51.2.5
+++ views_query.inc	16 Feb 2007 13:04:48 -0000
@@ -331,13 +337,12 @@
   /*
    * Set the base field to be distinct.
    */
-  function set_distinct() {
-    if (count($this->fields) && substr($this->fields[0], 0, 8) != 'DISTINCT') {
-      $field = $this->fields[0];
-      $this->fields[0] = "DISTINCT($field)";
-      $this->count_field = "DISTINCT($field)";
+  function set_distinct($value = TRUE) {
+    if (!($this->no_distinct && $value)) {
+      $this->distinct = $value;
     }
   }
+
   /*
    * Remove all fields that may've been added; primarily used for summary
    * mode where we're changing the query because we didn't get data we needed.
@@ -561,6 +566,13 @@
   function query($getcount = false) {
     $table_data = _views_get_tables();
 
+    // Set distinct
+    if ($this->distinct && count($this->fields)) {
+      $field = $this->fields[0];
+      $this->fields[0] = "DISTINCT($field)";
+      $this->count_field = "DISTINCT($this->count_field)";
+    }
+
     // Add all the tables to the query via joins. We assume all LEFT joins.
     foreach ($this->tablequeue as $tinfo) {
       $table = $tinfo['table'];
@@ -596,10 +608,11 @@
       }
     }
 
-    // If it's not a count query, add our fields
-    if (!$getcount) {
+    // If it's not a count query that is not using distinct, add our fields
+    if (!($getcount && !$this->distinct)) {
       $fields = implode(', ', $this->fields);
-
+    }
+    if (!$getcount) {
       // we only add the groupby if we're not counting.
       if ($this->groupby) {
         $groupby = "GROUP BY " . implode(', ', $this->groupby);
