Index: trunk/ippTools/share/magictool_definebyquery_select.sql
===================================================================
--- trunk/ippTools/share/magictool_definebyquery_select.sql	(revision 26033)
+++ trunk/ippTools/share/magictool_definebyquery_select.sql	(revision 26039)
@@ -1,5 +1,5 @@
 -- Get a list of exposures on which magic may be performed
 SELECT DISTINCT
-    exp_id,
+    chipRun.exp_id,
     MAX(diffWarps.diff_id) AS diff_id,
     -- The following trick pulls out the 'inverse' value for the maximum diff_id
@@ -33,5 +33,10 @@
 JOIN camRun USING(cam_id)
 JOIN chipRun USING(chip_id)
-LEFT JOIN magicRun USING(exp_id)
+LEFT JOIN
+    (SELECT magic_id, exp_id, label
+        FROM magicRun 
+        -- rerun hook %s
+    ) AS oldMagicRun
+    ON oldMagicRun.exp_id = chipRun.exp_id
 -- WHERE hook %s
-GROUP BY exp_id
+GROUP BY chipRun.exp_id
