Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 8541)
+++ trunk/ippTools/src/dettool.c	(revision 8565)
@@ -724,9 +724,33 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // no options are required... use the default where statement
-    psArray *inputExp = detInputExpSelectRowObjects(config->dbh, config->where, 
-            0);
-    if (!inputExp) {
-        psError(PS_ERR_UNKNOWN, false, "no rawDetrendExp rows found");
+    // select detInputExp.*
+    // select rawDetrendExp.*
+    // by:
+    // exp_id
+
+    psString query = psStringCopy(
+        "SELECT DISTINCT *"
+        " FROM detInputExp"
+        " JOIN rawDetrendExp"
+        " USING(exp_id)"
+        ); 
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereSQL(config->where, "detInputExp");
+        psStringAppend(&query, " %s", whereClause);
+        psFree(whereClause);
+    }
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    } 
+    psFree(query);
+
+    psArray *output = p_psDBFetchResult(config->dbh);
+    if (!output) {
+        // XXX check psError here
+        psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found");
         return false;
     }
@@ -742,14 +766,12 @@
     }
 
-    if (psArrayLength(inputExp)) {
-        // negative simple so the default is true
-        if (!detInputExpPrintObjects(stdout, inputExp, !simple)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to print array");
-            psFree(inputExp);
-            return false;
-        }
-    }
-
-    psFree(inputExp);
+    // negative simple so the default is true
+    if (!ippdbPrintMetadatas(stdout, output, "detInputExp", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
 
     return true;
