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

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -