sorting - Sort by field values in MySQL Query -


i have mysql table named tbl_posts columns title,category,timestamp.

title  category  timestamp cat    animal    2014-12-12 05:54:49  rose   flower    2014-12-12 05:54:50 apple  fruit     2014-12-12 05:54:51 dog    animal    2014-12-12 05:54:52 

i want mysql query sort according category. when search category 'animal', cat , dog wants show first , after append other categories too. desired output follows

   title  category  timestamp     dog    animal    2014-12-12 05:54:52     cat    animal    2014-12-12 05:54:49      rose   flower    2014-12-12 05:54:50     apple  fruit     2014-12-12 05:54:51 

thanks in advance.

select distinct y.*    my_table x    join my_table y      on y.category = x.category    order      y.title = 'dog' desc      , y.category; 

or that


Comments

Popular posts from this blog

java - Unable to make sub reports with Jasper -

scala - play framework: Modules were resolved with conflicting cross-version suffixes -

Save and close a word document by giving a name in R -