sql - mysql multiple join with same table and grouping by category -
i need query
last news grouping category (category limit 5) , order published_at. me?
tables
news
1. id 2. caption 3. published_at
category
1. id 2. name
news_has_category
1. news_id 2. category_id
sample output
caption01.. 2016-01-28 category_id = 4 caption02.. 2016-01-27 category_id = 4 caption03.. 2016-01-26 category_id = 4 caption04.. 2016-01-25 category_id = 4 caption05.. 2016-01-24 category_id = 4 caption06.. 2016-01-28 category_id = 3 caption07.. 2016-01-27 category_id = 3 caption08.. 2016-01-26 category_id = 3 caption09.. 2016-01-25 category_id = 3 caption10.. 2016-01-24 category_id = 3 caption11.. 2016-01-28 category_id = 6 caption12.. 2016-01-27 category_id = 6 caption13.. 2016-01-26 category_id = 6 caption14.. 2016-01-25 category_id = 6 caption15.. 2016-01-24 category_id = 6
i tried creating tables in mysql per table structure. first need group category , date in grouped category understand.
select caption , published_at,category_id news,news_has_cat id = news_id order category_id desc,published_at;
the above query gives output reverse ordered category , date in ascending order in case. had below query meet requirement.
select caption , published_at,category_id news,news_has_cat id = news_id order category_id desc,published_at desc;
try out
Comments
Post a Comment