Object query language | execute both "order by" and "where" clauses
How do I sort out some data according to an where clause and a order by clause using object query language this is the query that I'm using but i'm not sure if it is working o开发者_Python百科r not.
SELECT user from user.User as user WHERE user.status=1 order by user.username
Thanks.
Your query looks fine. From the reference documentation:
14.11. The order by clause
The list returned by a query can be ordered by any property of a returned class or components:
from DomesticCat cat order by cat.name asc, cat.weight desc, cat.birthdate
The optional asc or desc indicate ascending or descending order respectively.
I think it should be written more like
SELECT `users`.* FROM `users` WHERE `users`.`status` = 1 ORDER BY `users`.`username`
This assumes you have a table called users
and want to select all rows where status
is 1
, ordered by the username column.
精彩评论