diff --git a/core/DataAccess/LogQueryBuilder.php b/core/DataAccess/LogQueryBuilder.php
index 132480514b5036d9d0b79cab5688f82bda1de6d7..b062b91b3fa2ed84fe9d5afe13298abce24798fb 100644
--- a/core/DataAccess/LogQueryBuilder.php
+++ b/core/DataAccess/LogQueryBuilder.php
@@ -185,9 +185,14 @@ class LogQueryBuilder
         $innerFrom = $from;
         $innerWhere = $where;
         $innerGroupBy = "log_visit.idvisit";
-        $innerOrderBy = "NULL";
         $innerLimit = $limit;
 
+        $innerOrderBy = "NULL";
+        // Only when there is a LIMIT then we can apply to the inner query the same ORDER BY as the parent query
+        if($innerLimit) {
+            $innerOrderBy = $orderBy;
+        }
+
         $innerQuery = $this->buildSelectQuery($innerSelect, $innerFrom, $innerWhere, $innerGroupBy, $innerOrderBy, $innerLimit);
 
         $select = preg_replace('/'.$matchTables.'\./', 'log_inner.', $select);
diff --git a/plugins/Live/tests/System/ModelTest.php b/plugins/Live/tests/System/ModelTest.php
index d5dea34767709a466fc6c36a948246a297e34c53..90196e73095a51bde598df85c55427cdee89a7e0 100644
--- a/plugins/Live/tests/System/ModelTest.php
+++ b/plugins/Live/tests/System/ModelTest.php
@@ -92,7 +92,7 @@ class ModelTest extends SystemTestCase
                           AND log_visit.visit_last_action_time <= ? )
                           AND ( log_link_visit_action.custom_var_k1 = ? )
                         GROUP BY log_visit.idvisit
-                        ORDER BY NULL
+                        ORDER BY idsite, visit_last_action_time DESC
                         LIMIT 100
                         ) AS log_inner
                     ORDER BY idsite, visit_last_action_time DESC