diff --git a/include/class.orm.php b/include/class.orm.php
index 36f666b5c50ced84087b40a4949c0f6834ee3330..f961d39440dcbdc57db64f522a38db867969e9ad 100644
--- a/include/class.orm.php
+++ b/include/class.orm.php
@@ -2324,7 +2324,7 @@ class MySqlCompiler extends SqlCompiler {
      */
     function input($what, $slot=false, $model=false) {
         if ($what instanceof QuerySet) {
-            $q = $what->getQuery(array('nosort'=>true));
+            $q = $what->getQuery(array('nosort'=>!($what->limit || $what->offset)));
             // Rewrite the parameter numbers so they fit the parameter numbers
             // of the current parameters of the $compiler
             $self = $this;
diff --git a/include/class.ticket.php b/include/class.ticket.php
index c97607c959e6de649970f5fa551e4c4c86a04772..d2a85ae8c3eb0b621386e70f3e58e12c7852aabb 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -708,15 +708,17 @@ implements RestrictedAccess, Threadable {
 
     function getLastRespondent() {
         if (!isset($this->lastrespondent)) {
+            if (!$this->thread || !$this->thread->entries)
+                return $this->lastrespondent = false;
             $this->lastrespondent = Staff::objects()
                 ->filter(array(
-                'staff_id' => static::objects()
+                'staff_id' => $this->thread->entries
                     ->filter(array(
-                        'thread__entries__type' => 'R',
-                        'thread__entries__staff_id__gt' => 0
+                        'type' => 'R',
+                        'staff_id__gt' => 0,
                     ))
-                    ->values_flat('thread__entries__staff_id')
-                    ->order_by('-thread__entries__id')
+                    ->values_flat('staff_id')
+                    ->order_by('-id')
                     ->limit(1)
                 ))
                 ->first()
@@ -2245,8 +2247,8 @@ implements RestrictedAccess, Threadable {
             // Build list of recipients and fire the alerts.
             $recipients = array();
             //Last respondent.
-            if ($cfg->alertLastRespondentONNewMessage() || $cfg->alertAssignedONNewMessage())
-                $recipients[] = $this->getLastRespondent();
+            if ($cfg->alertLastRespondentONNewMessage() && ($lr = $this->getLastRespondent()))
+                $recipients[] = $lr;
 
             //Assigned staff if any...could be the last respondent
             if ($cfg->alertAssignedONNewMessage() && $this->isAssigned()) {