Index: /trunk/ippTools/share/difftool_pendingcleanuprun.sql
===================================================================
--- /trunk/ippTools/share/difftool_pendingcleanuprun.sql	(revision 32217)
+++ /trunk/ippTools/share/difftool_pendingcleanuprun.sql	(revision 32218)
@@ -2,5 +2,5 @@
 -- all of this is just to get the camera used for the diff run
 SELECT DISTINCT * FROM 
-   (SELECT 
+   (SELECT DISTINCT
 	    diffRun.diff_id,
 	    rawExp.camera,
@@ -29,6 +29,7 @@
              diffRun.state = 'goto_scrubbed' OR 
 	     diffRun.state = 'goto_purged')
+	@INNERLIMITS@
      UNION
-     SELECT
+     SELECT DISTINCT
 	    diffRun.diff_id,
 	    rawExp.camera,
@@ -57,6 +58,7 @@
              diffRun.state = 'goto_scrubbed' OR 
 	     diffRun.state = 'goto_purged')
+	@INNERLIMITS@
      UNION
-     SELECT
+     SELECT DISTINCT 
 	    diffRun.diff_id,
 	    rawExp.camera,
@@ -85,6 +87,7 @@
              diffRun.state = 'goto_scrubbed' OR 
 	     diffRun.state = 'goto_purged')
+	@INNERLIMITS@
      UNION
-     SELECT
+     SELECT DISTINCT
 	    diffRun.diff_id,
 	    rawExp.camera,
@@ -113,4 +116,5 @@
              diffRun.state = 'goto_scrubbed' OR 
 	     diffRun.state = 'goto_purged')
+	@INNERLIMITS@
 	) as Foo
 	WHERE 1
Index: /trunk/ippTools/src/difftool.c
===================================================================
--- /trunk/ippTools/src/difftool.c	(revision 32217)
+++ /trunk/ippTools/src/difftool.c	(revision 32218)
@@ -2461,5 +2461,10 @@
         psString limitString = psDBGenerateLimitSQL(limit);
         psStringAppend(&query, " %s", limitString);
+	psStringSubstitute(&query,limitString,"@INNERLIMITS@");
         psFree(limitString);
+
+    }
+    else {
+      psStringSubstitute(&query,NULL,"@INNERLIMITS@");
     }
     //    fprintf(stderr,"%s",query);
