Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GROUP BY query ignores ORDER BY clause

Tags:

sql

mysql

SELECT
    deal_woot.*,
    site.woot_off,
    site.name AS site_name
FROM deal_woot
INNER JOIN site ON site.id = site_id
WHERE site_id IN (2, 3, 4, 5, 6)
GROUP BY site_id
ORDER BY deal_woot.id DESC
LIMIT 5

I'd like to ORDER BY before grouping, how can I accomplish this?

like image 852
Webnet Avatar asked Nov 26 '22 15:11

Webnet


1 Answers

With a sub-query like: SELECT *,COUNT(*) FROM (SELECT * from actions order by date DESC) AS actions GROUP BY ip;

like image 154
servermanfail Avatar answered Nov 28 '22 03:11

servermanfail