Index: trunk/ippTools/src/difftool.c
===================================================================
--- trunk/ippTools/src/difftool.c	(revision 11974)
+++ trunk/ippTools/src/difftool.c	(revision 11979)
@@ -104,4 +104,24 @@
     }
 
+    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
+        return false;
+    }
+    if (!skycell_id) {
+        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
+        return false;
+    }
+
+    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
+        return false;
+    }
+    if (!tess_id) {
+        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
+        return false;
+    }
+
     psTime *registered = NULL;
     {
@@ -124,5 +144,7 @@
             workdir,
             NULL,       // dvodb
-            registered
+            registered,
+            skycell_id,
+            tess_id
     );
     psFree(registered);
@@ -390,11 +412,7 @@
         " LEFT JOIN p5DiffScfile\n"
         "   ON p5InputScfile.p5_id      = p5DiffScfile.p5_id\n"
-        "  AND p5InputScfile.skycell_id = p5DiffScfile.skycell_id\n"
-        "  AND p5InputScfile.tess_id    = p5DiffScfile.tess_id\n"
         " WHERE\n"
         "   p5Run.state = 'run'\n" 
         "   AND p5DiffScfile.p5_id IS NULL\n"
-        "   AND p5DiffScfile.skycell_id IS NULL\n"
-        "   AND p5DiffScfile.tess_id IS NULL\n"
     );
 
@@ -479,24 +497,4 @@
     }
 
-    psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");
-        return false;
-    }
-    if (!skycell_id) {
-        psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");
-        return false;
-    }
-
-    psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");
-        return false;
-    }
-    if (!tess_id) {
-        psError(PS_ERR_UNKNOWN, true, "-tess_id is required");
-        return false;
-    }
-
     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     if (!status) {
@@ -525,6 +523,4 @@
     if (!p5DiffScfileInsert(config->dbh, 
             (psS32)atoi(p5_id),
-            skycell_id,
-            tess_id,
             uri,
             bg,
@@ -553,4 +549,6 @@
     psString query = psStringCopy( 
         "SELECT\n"
+        "   p5Run.skycell_id,\n"
+        "   p5Run.tess_id,\n"
         "   p5DiffScfile.*\n"
         " FROM p5Run\n"
