Check out example codes for "group by sql not ordering issues". It will help you in understanding the concepts better.

Code Example 1

SELECT * FROM(
SELECT DISTINCT(item_id),balance
FROM `stock_activity` 

ORDER BY(activity_id) DESC
) t1
GROUP BY (item_id)

Learn ReactJs, React Native from akashmittal.com