Index: trunk/ippTools/share/Makefile.am
===================================================================
--- trunk/ippTools/share/Makefile.am	(revision 26144)
+++ trunk/ippTools/share/Makefile.am	(revision 26147)
@@ -247,6 +247,5 @@
      stacktool_definebyquery_insert_random_part1.sql \
      stacktool_definebyquery_insert_random_part2.sql \
-     stacktool_definebyquery_part1.sql \
-     stacktool_definebyquery_part2.sql \
+     stacktool_definebyquery_select.sql \
      stacktool_definebyquery_test.sql \
      stacktool_donecleanup.sql \
Index: trunk/ippTools/share/stacktool_definebyquery_part1.sql
===================================================================
--- trunk/ippTools/share/stacktool_definebyquery_part1.sql	(revision 26144)
+++ 	(revision )
@@ -1,31 +1,0 @@
--- This is the first part of the query to get a list of skycells with
--- warps to be stacked, along with the number of warps already in a
--- stack.  It needs to be completed by part 2 (see below).
-
-SELECT
-    skycell_id,
-    filter,
-    tess_id,
-    num_warp,
-    MAX(num_stack) AS num_stack
-FROM ((
-    -- Number of stack-ready warps as a function of skycell and filter
-    SELECT
-        skycell_id,
-        warpSkyfile.tess_id as tess_id,
-        rawExp.filter,
-        COUNT(warpSkyfile.skycell_id) AS num_warp -- number of warps that can be stacked
-    FROM warpRun
-    JOIN warpSkyfile USING(warp_id)
-    JOIN fakeRun USING(fake_id)
-    JOIN camRun USING(cam_id)
-    JOIN camProcessedExp USING(cam_id)
-    JOIN chipRun USING(chip_id)
-    JOIN rawExp USING(exp_id)
-    WHERE
-        warpRun.state = 'full'
-        AND warpSkyfile.fault = 0
-        AND warpSkyfile.quality = 0
-    -- Here should follow the SQL in stacktool_definebyquery_part2.sql,
-    -- after any additional WHERE conditions have been added
-
Index: trunk/ippTools/share/stacktool_definebyquery_part2.sql
===================================================================
--- trunk/ippTools/share/stacktool_definebyquery_part2.sql	(revision 26144)
+++ 	(revision )
@@ -1,28 +1,0 @@
-
--- This is the second part of the query to get a list of skycells with
--- warps to be stacked, along with the number of warps already in a
--- stack.  It should follow part 1, which is in
--- stacktool_definebyquery_part1.sql
-
-    GROUP BY
-        skycell_id,
-        filter
-        ) AS warpsToStack
-        LEFT JOIN (
-    -- Number of stack inputs as a function of skycell and filter
-    SELECT
-        skycell_id,
-	stackRun.tess_id as stack_tess_id,
-        filter,
-        COUNT(stackInputSkyfile.warp_id) as num_stack -- number of warps in a stack
-    FROM stackRun
-        JOIN stackInputSkyfile USING(stack_id)
-    GROUP BY
-        stack_id
-        ) AS stackSizes
-    -- JOINing the warpsToStack and stackSizes tables
-        USING(skycell_id, filter)
-        )
-    GROUP BY
-        skycell_id,
-        filter
Index: trunk/ippTools/share/stacktool_definebyquery_select.sql
===================================================================
--- trunk/ippTools/share/stacktool_definebyquery_select.sql	(revision 26147)
+++ trunk/ippTools/share/stacktool_definebyquery_select.sql	(revision 26147)
@@ -0,0 +1,52 @@
+-- This is a query to get a list of skycells with warps to be stacked,
+-- along with the number of warps already in a stack.
+
+SELECT
+    skycell_id,
+    filter,
+    tess_id,
+    num_warp,
+    MAX(num_stack) AS num_stack
+FROM ((
+    -- Number of stack-ready warps as a function of skycell and filter
+    SELECT
+        skycell_id,
+        warpSkyfile.tess_id as tess_id,
+        rawExp.filter,
+        COUNT(warpSkyfile.skycell_id) AS num_warp -- number of warps that can be stacked
+    FROM warpRun
+    JOIN warpSkyfile USING(warp_id)
+    JOIN fakeRun USING(fake_id)
+    JOIN camRun USING(cam_id)
+    JOIN camProcessedExp USING(cam_id)
+    JOIN chipRun USING(chip_id)
+    JOIN rawExp USING(exp_id)
+    WHERE
+        warpRun.state = 'full'
+        AND warpSkyfile.fault = 0
+        AND warpSkyfile.quality = 0
+    -- WHERE hook %s
+    GROUP BY
+        skycell_id,
+        filter
+    ) AS warpsToStack
+LEFT JOIN (
+    -- Number of stack inputs as a function of skycell and filter
+    SELECT
+        skycell_id,
+        stackRun.tess_id as stack_tess_id,
+        filter,
+        COUNT(stackInputSkyfile.warp_id) as num_stack -- number of warps in a stack
+    FROM stackRun
+    JOIN stackInputSkyfile USING(stack_id)
+    -- WHERE hook %s
+    GROUP BY
+        stack_id
+    ) AS stackSizes
+-- JOINing the warpsToStack and stackSizes tables
+    USING(skycell_id, filter)
+    )
+GROUP BY
+    skycell_id,
+    filter
+
