diff -Naur nss-mysql-1.0-new/src/group.c nss-mysql-1.0/src/group.c
--- nss-mysql-1.0-new/src/group.c	2006-03-01 11:43:10.000000000 +0000
+++ nss-mysql-1.0/src/group.c	2003-05-12 15:59:18.000000000 +0100
@@ -109,7 +109,8 @@
                 /* we look by name */
                 sql = _nss_mysql_sqlprintf("select %s,%s,%s,%s from %s "
                                 "LEFT JOIN %s on %s=%s LEFT JOIN %s on %s=%s "
-                                "and %s where %s = '%s' and %s",
+                                "and %s where %s = '%s' and %s order by "
+                                "%s,%s desc",
                         goptions->groupnamecolumn,
                         goptions->gidcolumn,
                         goptions->passwordcolumn,
@@ -131,17 +132,18 @@
                         /* where */
                         goptions->groupnamecolumn,
                         e_name,
-                        goptions->where[0] ? goptions->where : "1=1");
+                        goptions->where[0] ? goptions->where : "1=1",
+                        /* order by */
+                        goptions->groupnamecolumn,
+                        options->usercolumn);
                 if (call_free)
                         free(e_name);
         } else {
                 /* we look by GID */
-		if (q->gid > 1999)
-		{
-			q->gid-=2000;
-	                sql = _nss_mysql_sqlprintf("select %s,%s,%s,%s from %s "
+                sql = _nss_mysql_sqlprintf("select %s,%s,%s,%s from %s "
                                 "LEFT JOIN %s on %s=%s LEFT JOIN %s on %s=%s "
-                                "and %s where %s = %d and %s",
+                                "and %s where %s = %d and %s order by %s"
+                                ",%s desc",
                         goptions->groupnamecolumn,
                         goptions->gidcolumn,
                         goptions->passwordcolumn,
@@ -164,18 +166,10 @@
                         /* for bulk retrieval, we retrieve every entry */
                         q->bulk ? "1" : goptions->gidcolumn,
                         q->bulk ? 1 : q->gid,
-                        goptions->where[0] ? goptions->where : "1=1");
-		}
-		else
-		{
-			sql = _nss_mysql_sqlprintf("select %s,%s,%s,%s from %s,users where 1=0",
+                        goptions->where[0] ? goptions->where : "1=1",
+                        /* order by */
                         goptions->groupnamecolumn,
-                        goptions->gidcolumn,
-                        goptions->passwordcolumn,
-                        options->usercolumn,
-                        /* from */
-                        goptions->groupinfotable);
-		}
+                        options->usercolumn);
         }
 
         if (DEBUG)
diff -Naur nss-mysql-1.0-new/src/passwd.c nss-mysql-1.0/src/passwd.c
--- nss-mysql-1.0-new/src/passwd.c	2006-03-01 11:43:06.000000000 +0000
+++ nss-mysql-1.0/src/passwd.c	2003-05-12 15:59:18.000000000 +0100
@@ -102,7 +102,8 @@
         if (q->name) {
                 /* look up by name */
                 sql = _nss_mysql_sqlprintf("select %s,%s,%s,%s,%s,%s,%s from %s"
-                               " where %s='%s' and %s is not null and %s",
+                               " where %s='%s' and %s is not null and %s order"
+                               " by %s",
                         /* select */
                         options->usercolumn,
                         options->uidcolumn,
@@ -124,18 +125,16 @@
                         /* and */
                         options->uidcolumn,
                         /* is not null and */
-                        options->where[0] ? options->where : "1=1");
+                        options->where[0] ? options->where : "1=1",
+                        options->uidcolumn);
 
                 if (call_free)
                         free(e_name);
 
         } else {
                 /* look up by uid */
-		if (q->uid > 1999)
-		{
-			q->uid-=2000;
-	                sql = _nss_mysql_sqlprintf("select %s,%s,%s,%s,%s,%s,%s from %s"
-                                " where %s=%d and %s",
+                sql = _nss_mysql_sqlprintf("select %s,%s,%s,%s,%s,%s,%s from %s"
+                                " where %s=%d and %s order by %s",
                         /* select */
                         options->usercolumn,
                         options->uidcolumn,
@@ -156,26 +155,9 @@
                         /* = */
                         q->bulk ? 1 : q->uid,
                         /* and */
-                        options->where[0] ? options->where : "1=1"
+                        options->where[0] ? options->where : "1=1",
+                        options->uidcolumn
                         );
-		}
-		else
-                {
-	                sql = _nss_mysql_sqlprintf("select %s,%s,%s,%s,%s,%s,%s from %s WHERE 1=0",
-                        options->usercolumn,
-                        options->uidcolumn,
-#if ! USE_SHADOW
-                        options->passwdcolumn,
-#else
-                        "NULL",
-#endif
-                        options->realnamecolumn,
-                        options->shellcolumn,
-                        options->homedircolumn,
-                        options->gidcolumn,
-                        /* from */
-                        options->table);
-                }
         }
 
         if (DEBUG)
