Index: /trunk/ippTools/src/detselect.c
===================================================================
--- /trunk/ippTools/src/detselect.c	(revision 9439)
+++ /trunk/ippTools/src/detselect.c	(revision 9440)
@@ -102,19 +102,20 @@
         // "   detRunSummary.accept,"
         // "   rawDetrendExp.camera"
-	"  FROM detRun"
-	"  JOIN detRunSummary "
-	"    ON detRun.det_id = detRunSummary.det_id"
-	"  JOIN detInputExp"
-	"    ON detRunSummary.det_id = detInputExp.det_id"
-	"   AND detRunSummary.iteration = detInputExp.iteration"
-	"  JOIN rawImfile"
-	"    ON detInputExp.exp_tag = rawImfile.exp_tag"
-	"  JOIN rawDetrendExp"
-	"    ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
-	" WHERE detRun.state = 'stop'"
-	"   AND detRunSummary.accept = 1"
-	// XXX the following entry is needed to exclude db mismatched
-	// XXX these are caused by an error upstream and should be fixed
-        "   AND detRun.det_type = rawDetrendExp.object"
+        " FROM detRun"
+        " JOIN detRunSummary "
+        "   USING(det_id)"
+        " JOIN detInputExp"
+        "   ON detRunSummary.det_id = detInputExp.det_id"
+        "   AND detRunSummary.iteration = detInputExp.iteration"
+        " JOIN rawDetrendExp"
+        "   ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        " JOIN rawImfile"
+        "   ON rawDetrendExp.exp_tag = rawImfile.exp_tag"
+        " WHERE"
+        "   detRun.state = 'stop'"
+        "   AND detRunSummary.accept = 1"
+        // XXX the following entry is needed to exclude db mismatched
+        // XXX these are caused by an error upstream and should be fixed
+//        "   AND detRun.det_type = rawDetrendExp.object"
     );
 # endif
@@ -186,5 +187,5 @@
         " FROM detNormalizedImfile"
         " JOIN detRun"
-        "   ON detNormalizedImfile.det_id = detRun.det_id"
+        "   USING(det_id)"
         " JOIN detRunSummary"
         "   ON detNormalizedImfile.det_id = detRunSummary.det_id"
Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 9439)
+++ /trunk/ippTools/src/dettool.c	(revision 9440)
@@ -146,7 +146,13 @@
     PS_ASSERT_PTR_NON_NULL(config, NULL);
 
-     psString query = psStringCopy("SELECT rawDetrendExp.* FROM rawDetrendExp"
-        " LEFT JOIN detInputExp ON rawDetrendExp.exp_tag = detInputExp.exp_tag"
-        " WHERE detInputExp.exp_tag IS NULL");
+     psString query = psStringCopy(
+        "SELECT"
+        "   rawDetrendExp.*"
+        " FROM rawDetrendExp"
+        " LEFT JOIN detInputExp"
+        "   ON rawDetrendExp.exp_tag = detInputExp.exp_tag"
+        " WHERE"
+        "    detInputExp.exp_tag IS NULL"
+    );
 
     if (config->where) {
