Index: trunk/ippTools/share/difftool_inputskyfile.sql
===================================================================
--- trunk/ippTools/share/difftool_inputskyfile.sql	(revision 26179)
+++ trunk/ippTools/share/difftool_inputskyfile.sql	(revision 26180)
@@ -29,7 +29,4 @@
     JOIN rawExp
         USING(exp_id)
-    WHERE
-        (diffRun.state = 'new' or diffRun.state = 'full')
-        AND (warpRun.state = 'full')
         -- where hook %s
     UNION
@@ -63,7 +60,4 @@
     JOIN rawExp
         USING(exp_id)
-    WHERE
-        (diffRun.state = 'new' or diffRun.state = 'full')
-        AND (warpRun.state = 'full')
         -- where hook %s
     UNION
@@ -97,6 +91,4 @@
     JOIN rawExp
         USING(exp_id)
-    WHERE
-        (diffRun.state = 'new' or diffRun.state = 'full')
         -- where hook %s
     UNION
@@ -130,6 +122,5 @@
     JOIN rawExp
         USING(exp_id)
-    WHERE
-        (diffRun.state = 'new' or diffRun.state = 'full')
         -- where hook %s
     ) as Foo
+-- template where hook %s
Index: trunk/ippTools/src/difftool.c
===================================================================
--- trunk/ippTools/src/difftool.c	(revision 26179)
+++ trunk/ippTools/src/difftool.c	(revision 26180)
@@ -386,20 +386,16 @@
     if (psListLength(where->list)) {
         whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringPrepend(&whereClause, "\n AND ");
+        psStringPrepend(&whereClause, "\n WHERE ");
     }
     psFree(where);
 
     // Add condition to get only templates or only inputs
+    psString templateClause = NULL;
     {
-        psString templateClause = NULL;
         if (template) {
-            psStringAppend(&templateClause, " %s", " template != 0");
+            psStringAppend(&templateClause, "\n WHERE %s", " template != 0");
         } else if (input) {
-            psStringAppend(&templateClause, " %s", " template = 0");
-        }
-        if (templateClause) {
-            psStringAppend(&whereClause, "\n AND %s", templateClause);
-        }
-        psFree(templateClause);
+            psStringAppend(&templateClause, "\n WHERE %s", " template = 0");
+        }
     }
 
@@ -412,10 +408,12 @@
     }
 
-    if (!p_psDBRunQueryF(config->dbh, query, whereClause, whereClause, whereClause, whereClause)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
+    if (!p_psDBRunQueryF(config->dbh, query, whereClause, whereClause, whereClause, whereClause, templateClause)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(templateClause);
         psFree(whereClause);
         psFree(query);
         return false;
     }
+    psFree(templateClause);
     psFree(whereClause);
     psFree(query);
