So I am using room database to persist users locally, now users have this entity class:
@Entity
public class Users{
public string name;
public string email;
@PrimaryKey
public string id;
......
}
I retrieve all these users with a DAO that looks like this:
@DAO
public interface UsersDAO{
@Query("select * from Users")
public List<Users> getAllUsers();
}
The above DAO will read all users in the order they were added to the database.
Question:
Is it possible to query users by the name
field in Users
entity alphabetically?
Thanks.
Use the ORDER BY
keyword.
"select * from Users ORDER BY name"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With