MySQL: Order By Specific Fields -


first question ever harsh :)

i needing sort specific department type or department(s) followed rank. default setting orders rank, dept_type , department. front end php i'm looking more sql fix if possible. have source table of departments if sub query work.

orgin table:

+-----------+------------+------+ | dept_type | department | rank | +-----------+------------+------+ | inbound   | dept r     |   1  | | outbound  | dept p     |   2  | | inbound   | dept e     |   3  | | outbound  | dept d     |   4  | | outbound  | dept d     |   5  | | outbound  | dept d     |   6  | +-----------+------------+------+ 

i need specify order "dept d", "dept e", else so:

select *  table  order field(department, "dept d", "dept e"), rank, dept_type, department 

what want return (ddderp):

+-----------+------------+------+ | dept_type | department | rank | +-----------+------------+------+ | outbound  | dept d     |   4  | | outbound  | dept d     |   5  | | outbound  | dept d     |   6  | | inbound   | dept e     |   3  | | inbound   | dept r     |   1  | | outbound  | dept p     |   2  | +-----------+------------+------+ 

what returns(rpddde):

+-----------+------------+------+ | dept_type | department | rank | +-----------+------------+------+ | inbound   | dept r     |   1  | | outbound  | dept p     |   2  | | outbound  | dept d     |   4  | | outbound  | dept d     |   5  | | outbound  | dept d     |   6  | | inbound   | dept e     |   3  | +-----------+------------+------+ 

so in theory want:

order field("dept d", "dept e", department), rank 

but not work way. thank taking time @ it.

use desc attribute:

order field(department, 'dept e', 'dept d') desc, rank, dept_type, department


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -