<p>Having just stumbled across this issue myself, I found that in the orderBy parameter that while 'lastName' didn't order correctly, 'lastname' did.</p>

CC BY-SA 4.0
2023-01-24T19:46:35.443Z
Weird - but it works!
4midori
CC BY-SA 4.0
2023-02-06T15:56:04.937Z
Ahh... probably the database is configured to use a case-sensitive collation.
Brad Bell
CC BY-SA 4.0
2023-01-23T16:39:05.537Z
2023-01-23T16:39:05.537Z
cuppanukka
<p>Just did a simple test on a fresh install of the latest Craft with 3 users in a user group using this code and the output was what I'd expect:</p>

<pre><code>{% set users = craft.users.groupId(1).orderBy('lastName asc') %}

&lt;ul&gt;
    {% for user in users %}
        &lt;li&gt;{{ user.lastName }}, {{ user.firstName }}&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;
</code></pre>

<p>Gives:</p>

<ul>
<li>Aardvark, Adam</li>
<li>Meadows, Marc</li>
<li>Zimmerman, Bob</li>
</ul>

CC BY-SA 4.0
2019-11-16T02:05:43.237Z
Weird. I checked it pretty thoroughly before giving up.
4midori
CC BY-SA 4.0
2019-11-16T02:52:42.083Z
Are you using PostgreSQL by chance?
Brad Bell
CC BY-SA 4.0
2019-11-16T15:56:11.080Z
No, MySQL is the DB.
4midori
CC BY-SA 4.0
2019-11-18T05:17:30.593Z
in that case, ¯\_(ツ)_/¯
Brad Bell
CC BY-SA 4.0
2019-11-15T22:35:00.343Z
2019-11-15T22:35:00.343Z
Brad Bell
<p><strong>Craft 3.3.13</strong></p>

<p>This query does not order users correctly.</p>

<pre><code>{% set users = craft.users.groupId(3).orderBy('lastName asc') %}
</code></pre>

<p>Bug?</p>

<users><query><elementquery>
Simple user query with orderBy not working
# Simple user query with orderBy not working

(Asked by: username_0 on 2019-11-14)

Craft 3.3.13
This query does not order users correctly.
{% set users = craft.users.groupId(3).orderBy('lastName asc') %}

Bug?

**Tags:** users, query, elementquery

---

## 2 answers

### Answer by username_1 on 2023-01-23. Score: 2 | Accepted answer

Having just stumbled across this issue myself, I found that in the orderBy parameter that while 'lastName' didn't order correctly, 'lastname' did.

> **Comments:**
> **username_0**: Weird - but it works!  
> **username_2**: Ahh... probably the database is configured to use a case-sensitive collation.  

---

### Answer by username_2 on 2019-11-15. Score: 1

Just did a simple test on a fresh install of the latest Craft with 3 users in a user group using this code and the output was what I'd expect:
{% set users = craft.users.groupId(1).orderBy('lastName asc') %}


    {% for user in users %}
        {{ user.lastName }}, {{ user.firstName }}
    {% endfor %}


Gives:

Aardvark, Adam
Meadows, Marc
Zimmerman, Bob

> **Comments:**
> **username_0**: Weird. I checked it pretty thoroughly before giving up.  
> **username_2**: Are you using PostgreSQL by chance?  
> **username_0**: No, MySQL is the DB.  
> **username_2**: in that case, ¯\_(ツ)_/¯  

---

