0

I'm trying to make this query ordering by date before the group by. I already tried some "solutions" which i found on stackoverflow but nothing worked.

The query is working just fine expect ordering by date.

SELECT * 
FROM
    guth_matchtable g 
    JOIN smp_scout_match_application scma 
        ON scma.guthmatchid = g.guthmatchid 
    JOIN smp_scout_match_application_cost smac 
        ON scma.id = smac.applicationid 
WHERE scma.userid = 5997 
    AND g.teamidhome IN (6384) 
GROUP BY g.teamidhome,
    smac.coststype 
ORDER BY g.dateofmatch DESC ;
Ashwini Agarwal
  • 4,828
  • 2
  • 42
  • 59
  • 9
    'Ordering data before grouping data' makes no sense by definition of `ORDER BY` and `GROUP BY`. Be more specific with data structure and desired result. – Alma Do Sep 17 '13 at 11:33
  • Post some sample data and how you want the result. – Mihai Sep 17 '13 at 11:35
  • 2
    @Eduardo . . . You are making a false assumption about how MySQL `group by` chooses values for columns when they are not in the `group by` clause. Read the documentation (http://dev.mysql.com/doc/refman/5.7/en/group-by-extensions.html) and focus on the statement: "The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate." – Gordon Linoff Sep 17 '13 at 11:35
  • Did you look at these ? http://stackoverflow.com/a/5140850/2763765 OR http://stackoverflow.com/questions/5140785/mysql-order-before-group-by –  Sep 17 '13 at 11:38

0 Answers0