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
Post a Comment