Index: trunk/ippTools/src/staticskytool.c
===================================================================
--- trunk/ippTools/src/staticskytool.c	(revision 33385)
+++ trunk/ippTools/src/staticskytool.c	(revision 33919)
@@ -29,4 +29,5 @@
 
 #include "pxtools.h"
+#include "pxspace.h"
 #include "staticskytool.h"
 
@@ -131,4 +132,6 @@
     pxAddLabelSearchArgs(config, whereMD, "-select_data_group",    "stackRun.data_group",       "LIKE");
     pxAddLabelSearchArgs(config, whereMD, "-select_filter",        "stackRun.filter",           "LIKE");
+    PXOPT_COPY_F32(config->args, whereMD, "-select_glat_min",      "skycell.glat",              ">=");
+    PXOPT_COPY_F32(config->args, whereMD, "-select_glat_max",      "skycell.glat",              "<=");
 
     // find the number of requested filters:
@@ -390,7 +393,13 @@
 
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-sky_id",  "sky_id",   "==");
-    PXOPT_COPY_STR(config->args, where, "-label",   "label",    "==");
-    PXOPT_COPY_STR(config->args, where, "-state",   "state",    "==");
+    PXOPT_COPY_S64(config->args, where, "-sky_id",      "sky_id",   "==");
+    PXOPT_COPY_STR(config->args, where, "-label",       "staticskyRun.label",    "==");
+    PXOPT_COPY_STR(config->args, where, "-state",       "staticskyRun.state",    "==");
+    PXOPT_COPY_STR(config->args, where, "-tess_id",     "stackRun.tess_id",    "==");
+    PXOPT_COPY_STR(config->args, where, "-skycell_id",  "stackRun.skycell_id",    "==");
+    if (!pxskycellAddWhere(config, where)) {
+        psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments");
+        return false;
+    }
     if (!psListLength(where->list)) {
         psFree(where);
@@ -399,5 +408,5 @@
     }
 
-    psString query = psStringCopy("UPDATE staticskyRun");
+    psString query = psStringCopy("UPDATE staticskyRun JOIN staticskyInput USING(sky_id) JOIN stackRun using(stack_id) JOIN skycell USING(tess_id, skycell_id)");
 
     // pxUpdateRun gets parameters from config->args and updates
@@ -638,4 +647,5 @@
     PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE");
     PXOPT_COPY_S16(config->args, where, "-fault",      "staticskyResult.fault", "==");
+    pxskycellAddWhere(config, where);
     PXOPT_LOOKUP_S32(num_filters, config->args, "-num_filters", false, false);
 
