Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 9467)
+++ trunk/ippTools/src/dettool.c	(revision 9484)
@@ -1726,28 +1726,33 @@
     psString query = psStringCopy(
         "SELECT DISTINCT"
-        "     detRun.det_id AS det_id,"
-        "     detRun.det_type,"
-        "     detRun.iteration,"
-        "     rawDetrendExp.camera"
+        "   detRun.det_id,"
+        "   detRun.det_type,"
+        "   detRun.iteration,"
+// XXX determine if these fields are truely visible to HAVING without
+// explicitly selecting them
+//        "   rawDetrendExp.imfiles,"
+//        "   detStackedImfile.class_id"
         " FROM detRun"
         " JOIN detInputExp"
-        "     ON detRun.det_id = detInputExp.det_id"
-        "     AND detRun.iteration = detInputExp.iteration"
+        "   ON detRun.det_id = detInputExp.det_id"
+        "   AND detRun.iteration = detInputExp.iteration"
         " JOIN rawDetrendExp"
-        "     ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
+        "   ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
         " JOIN detStackedImfile"
-        "     ON detInputExp.det_id = detStackedImfile.det_id"
-        "     AND detInputExp.iteration = detStackedImfile.iteration"
+        "   ON detInputExp.det_id = detStackedImfile.det_id"
+        "   AND detInputExp.iteration = detStackedImfile.iteration"
         " LEFT JOIN detNormalizedStatImfile"
-        "     ON detRun.det_id = detNormalizedStatImfile.det_id"
-        "     AND detRun.iteration = detNormalizedStatImfile.iteration"
+        "   ON detStackedImfile.det_id = detNormalizedStatImfile.det_id"
+        "   AND detStackedImfile.iteration = detNormalizedStatImfile.iteration"
+        "   AND detStackedImfile.class_id = detNormalizedStatImfile.class_id"
         " WHERE"
         "   detRun.state = 'run'"
         "   AND detNormalizedStatImfile.det_id IS NULL"
         "   AND detNormalizedStatImfile.iteration IS NULL"
+        "   AND detNormalizedStatImfile.class_id IS NULL"
         " GROUP BY"
-        "     rawDetrendExp.exp_tag,"
-        "     detRun.iteration,"
-        "     detRun.det_id"
+        "   rawDetrendExp.exp_tag,"
+        "   detRun.iteration,"
+        "   detRun.det_id"
         " HAVING MAX(rawDetrendExp.imfiles) = COUNT(detStackedImfile.class_id)"
         );
