diff --git a/db/migrations/6.0.7_add_consecutive_flag_for_consultations.php b/db/migrations/6.0.7_add_consecutive_flag_for_consultations.php
index 52b623da83e1f3b7e778f0a752571f0f4b757749..9c45a2a890201d940b6055c7d86cbdfe670078b9 100644
--- a/db/migrations/6.0.7_add_consecutive_flag_for_consultations.php
+++ b/db/migrations/6.0.7_add_consecutive_flag_for_consultations.php
@@ -21,7 +21,7 @@ return new class extends Migration
                   JOIN consultation_slots AS s1
                     ON s1.slot_id = (
                       SELECT slot_id
-                      FROM consultation_slots AS s2
+                      FROM (SELECT slot_id, block_id, start_time FROM consultation_slots) AS s2
                       WHERE s2.block_id = s0.block_id
                         AND s2.start_time < s0.start_time
                         AND s2.slot_id != s0.slot_id