Index: trunk/ippTools/share/stacktool_definebyquery_test.sql
===================================================================
--- trunk/ippTools/share/stacktool_definebyquery_test.sql	(revision 18579)
+++ trunk/ippTools/share/stacktool_definebyquery_test.sql	(revision 18609)
@@ -11,5 +11,9 @@
 -- stacktool_definebyquery_part1.sql
 SELECT
-    *
+    skycell_id,
+    tess_id,
+    filter,
+    num_warp,
+    MAX(num_stack) AS num_stack
 FROM ((
     -- Number of stack-ready warps as a function of skycell and filter
@@ -30,5 +34,4 @@
     AND warpSkyfile.fault = 0
     -- Any additional selection on warps/exposures goes here
-
 -- stacktool_definebyquery_part2.sql
     GROUP BY
@@ -42,5 +45,4 @@
         tess_id,
         filter,
-        stack_id,
         COUNT(stackInputSkyfile.warp_id) as num_stack -- number of warps in a stack
     FROM stackRun
@@ -48,9 +50,4 @@
     GROUP BY
         stack_id
-    -- This ORDER BY is important: it sets the final num_stack that
-    -- comes out of the top-level GROUP BY.  We want it to be the
-    -- biggest number for a skycell/filter combination.
-    ORDER BY
-        num_stack DESC
         ) AS stackSizes
     -- JOINing the warpsToStack and stackSizes tables
