diff --git a/lib/plugins/authmysql/auth.php b/lib/plugins/authmysql/auth.php
index 3ebd5123f67250fe0ba14e76adf7d0e529b2765c..1e6e6a4a97eb49ee1451627d6f8d0345e700ef39 100644
--- a/lib/plugins/authmysql/auth.php
+++ b/lib/plugins/authmysql/auth.php
@@ -358,7 +358,12 @@ class auth_plugin_authmysql extends DokuWiki_Auth_Plugin {
         if($this->_openDB()) {
             $this->_lockTables("READ");
             $sql = $this->_createSQLFilter($this->getConf('getUsers'), $filter);
-            $sql .= " ".$this->getConf('SortOrder')." LIMIT $first, $limit";
+            $sql .= " ".$this->getConf('SortOrder');
+            if($limit) {
+                $sql .= " LIMIT $first, $limit";
+            } elseif($first) {
+                $sql .= " LIMIT $first";
+            }
             $result = $this->_queryDB($sql);
 
             if(!empty($result)) {
diff --git a/lib/plugins/authpgsql/auth.php b/lib/plugins/authpgsql/auth.php
index 240db80fa98809d36feab9899d65b208fcf5003f..e51b39858148a782e0dddc5c5f990442483b11c1 100644
--- a/lib/plugins/authpgsql/auth.php
+++ b/lib/plugins/authpgsql/auth.php
@@ -154,7 +154,9 @@ class auth_plugin_authpgsql extends auth_plugin_authmysql {
         if($this->_openDB()) {
             $this->_lockTables("READ");
             $sql = $this->_createSQLFilter($this->conf['getUsers'], $filter);
-            $sql .= " ".$this->conf['SortOrder']." LIMIT $limit OFFSET $first";
+            $sql .= " ".$this->conf['SortOrder'];
+            if($limit) $sql .= " LIMIT $limit";
+            if($first) $sql .= " OFFSET $first";
             $result = $this->_queryDB($sql);
 
             foreach($result as $user)