diff --git a/sql/procedures.mysql b/sql/procedures.mysql
index 9d87e7d7faa2e9b211a12ecc3c97626bac62c55c..5c1d9582a7bc628b6f1ee85bdd9d980f513a11af 100644
--- a/sql/procedures.mysql
+++ b/sql/procedures.mysql
@@ -35,8 +35,8 @@ CREATE OR REPLACE VIEW msg AS
     SELECT a.analysis_id, a.logic_name, m.*
     FROM log_message m
     JOIN worker w USING (worker_id)
-    LEFT JOIN analysis_base a ON (a.analysis_id=w.analysis_id)
-    LEFT JOIN job j ON (j.job_id=m.job_id);
+    LEFT JOIN job j ON (j.job_id=m.job_id)
+    LEFT JOIN analysis_base a ON (a.analysis_id=j.analysis_id);
 
 
 #### time an analysis or group of analyses (given by a name pattern) ######################################
diff --git a/sql/procedures.sqlite b/sql/procedures.sqlite
index 51bb195d51a7e08808af1544ffff0caa22b0df55..176a46359d2fb62435ca5ec351ec1be0ceedd289 100644
--- a/sql/procedures.sqlite
+++ b/sql/procedures.sqlite
@@ -35,6 +35,6 @@ CREATE VIEW IF NOT EXISTS msg AS
     SELECT a.analysis_id, a.logic_name, m.*
     FROM log_message m
     JOIN worker w USING (worker_id)
-    LEFT JOIN analysis_base a ON (a.analysis_id=w.analysis_id)
-    LEFT JOIN job j ON (j.job_id=m.job_id);
+    LEFT JOIN job j ON (j.job_id=m.job_id)
+    LEFT JOIN analysis_base a ON (a.analysis_id=j.analysis_id);