Index: trunk/ippTools/share/difftool_definebyquery.sql
===================================================================
--- trunk/ippTools/share/difftool_definebyquery.sql	(revision 20682)
+++ trunk/ippTools/share/difftool_definebyquery.sql	(revision 20973)
@@ -9,7 +9,7 @@
     warpsToDiff.good_frac,
     warpsToDiff.diff_id,
-    warpsToDiff.kind,
     current_stack_id,
-    best_stack_id
+    best_stack_id,
+    exp_id
 FROM (
     -- Get list of warps that can be diffed, with any associated diff
@@ -23,6 +23,6 @@
         warpRun.label as warp_label,
         diffInputs.diff_id,
-        diffInputs.kind,
-        diffTemplates.stack_id AS current_stack_id
+        diffInputs.stack2 AS current_stack_id,
+        rawExp.exp_id
     FROM warpSkyfile
     JOIN warpRun USING(warp_id)
@@ -33,11 +33,7 @@
     -- Check if it has an associated diff
     LEFT JOIN diffInputSkyfile AS diffInputs
-        ON diffInputs.warp_id = warpSkyfile.warp_id
+        ON diffInputs.warp1 = warpSkyfile.warp_id
         AND diffInputs.skycell_id = warpSkyfile.skycell_id
-        AND diffInputs.template = 0 -- only join input files
-    -- Get the stack_id currently used as a template, if any
-    LEFT JOIN diffInputSkyfile AS diffTemplates
-        ON diffTemplates.diff_id = diffInputs.diff_id
-        AND diffTemplates.template != 0 -- only join template files
+        AND diffInputs.stack2 IS NOT NULL
     WHERE
         warpSkyfile.fault = 0
