mysql - GROUP BY and ORDER BY issues -


i have following query:

select distinct ( s.styletitle ), count(p.id) `picturecount`  `style` s left join  `instagram_picture_style` ps on s.id = ps.style_id left join  `instagram_shop_picture` p on ps.picture_id = p.id left join  `instagram_picture_category` c on c.picture_id = p.id left join  `instagram_second_level_category` sl on c.second_level_category_id = sl.id sl.id =25 group p.id order picturecount 

however query gives me:

enter image description here

i wanted list ordered style has pictures in it. did wrong? why giving me 1 on of styles, pretty sure has more pictures style

order by doesn't have underscores. equally important, using distinct in way seem think function. not. modifies on select , applies columns.

you should group by same column have in distinct. this:

select s.styletitle, count(p.id) `picturecount`  `style` s left join  `instagram_picture_style` ps on s.id = ps.style_id left join  `instagram_shop_picture` p on ps.picture_id = p.id left join  `instagram_picture_category` c on c.picture_id = p.id left join  `instagram_second_level_category` sl on c.second_level_category_id = sl.id sl.id  = 25 group s.styletitle order picturecount desc; 

in fact, never need distinct group by. if using, need think why necessary.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -