MySQL Sorting using order by not working using unio -


i'm using union statement in mysql i've problems sorting results. order statement doesn't works @ all, results comes out sorted id field.

here example query:

select a.* ( ( select * ticket_ticket t1 ticket_active=1 order t1.ticket_date_last_modified desc )  union ( select * ticket_ticket t2 ticket_active=0 order t2.ticket_date_last_modified desc, t2.ticket_status_id desc ) ) limit 0,20; 

i want order results of first select last_modified time, , second select time , status. order statement skipped. results come out ordered ticket_id ( primary key ). what's wrong in query ?

thanks!

ok, i've fixed writing query way:

select a.*  (select *   ticket_ticket  ticket_active=1  order ticket_date_last_modified desc) union select b.* (select *  ticket_ticket  ticket_active=0  order ticket_date_last_modified desc, ticket_status_id desc) b limit 0,                                                                           20; 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -