mysql - First order by (condition) and then by (condition) -
i want order sql request depending upon first user's statut , upon username. statut set column user_type
: 1=active, 2=inactive , 3=founder.
i use request doesn't work because want include in "active" members actives users (1) , founders (3) :
select user_type, callsign, username, vid, 0php_hub_chef.hub_id id_hub 0php_users left join phpbb_users on phpbb_id = phpbb_users.user_id left join 0php_hub_chef on 0php_hub_chef.user_id = phpbb_users.user_id 0php_users.hub_id = 29 order user_type <> 1, username_clean asc
i : order user_type <> 1 , 3, username_clean asc
have idea?
you can use in
:
order user_type in (1, 3) desc, username_clean asc
in mysql, boolean expression treated integer in integer context. if user_type
1 or 3, evaluates 1 else 0 -- hence desc
.
if don't desc
, can use not in
:
order user_type not in (1, 3), username_clean
Comments
Post a Comment