Index: /branches/eam_branches/ipp-pstamp-20260421/ippTools/share/difftool_pendingcleanuprun.sql
===================================================================
--- /branches/eam_branches/ipp-pstamp-20260421/ippTools/share/difftool_pendingcleanuprun.sql	(revision 43095)
+++ /branches/eam_branches/ipp-pstamp-20260421/ippTools/share/difftool_pendingcleanuprun.sql	(revision 43096)
@@ -1,6 +1,6 @@
 -- does this result in too many entries (one for each diffInputSkyfile?)
 -- all of this is just to get the camera used for the diff run
-SELECT DISTINCT * FROM 
-   (SELECT DISTINCT
+SELECT * FROM 
+   ((SELECT DISTINCT
 	    diffRun.diff_id,
 	    rawExp.camera,
@@ -31,7 +31,7 @@
              diffRun.state = 'goto_scrubbed' OR 
 	     diffRun.state = 'goto_purged')
-	@INNERLIMITS@
+	@INNERLIMITS@)
      UNION
-     SELECT DISTINCT
+     (SELECT DISTINCT
 	    diffRun.diff_id,
 	    rawExp.camera,
@@ -62,7 +62,7 @@
              diffRun.state = 'goto_scrubbed' OR 
 	     diffRun.state = 'goto_purged')
-	@INNERLIMITS@
+	@INNERLIMITS@)
      UNION
-     SELECT DISTINCT 
+     (SELECT DISTINCT 
 	    diffRun.diff_id,
 	    rawExp.camera,
@@ -93,7 +93,7 @@
              diffRun.state = 'goto_scrubbed' OR 
 	     diffRun.state = 'goto_purged')
-	@INNERLIMITS@
+	@INNERLIMITS@)
      UNION
-     SELECT DISTINCT
+     (SELECT DISTINCT
 	    diffRun.diff_id,
 	    rawExp.camera,
@@ -124,5 +124,5 @@
              diffRun.state = 'goto_scrubbed' OR 
 	     diffRun.state = 'goto_purged')
-	@INNERLIMITS@
+	@INNERLIMITS@)
 	) as Foo
 	WHERE 1
Index: /branches/eam_branches/ipp-pstamp-20260421/ippTools/src/difftool.c
===================================================================
--- /branches/eam_branches/ipp-pstamp-20260421/ippTools/src/difftool.c	(revision 43095)
+++ /branches/eam_branches/ipp-pstamp-20260421/ippTools/src/difftool.c	(revision 43096)
@@ -2883,11 +2883,11 @@
     if (limit) {
         psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psStringSubstitute(&query,limitString,"@INNERLIMITS@");
+        // psStringAppend(&query, " %s", limitString);
+        psStringSubstitute(&query, limitString, "@INNERLIMITS@");
         psFree(limitString);
 
     }
     else {
-      psStringSubstitute(&query,NULL,"@INNERLIMITS@");
+      psStringSubstitute(&query ,NULL, "@INNERLIMITS@");
     }
     //    fprintf(stderr,"%s",query);
