{"id":30451,"date":"2019-04-10T17:17:46","date_gmt":"2019-04-10T08:17:46","guid":{"rendered":"https:\/\/jirak.net\/wp\/removal-of-implicit-and-explicit-sorting-for-group-by\/"},"modified":"2019-04-10T17:34:27","modified_gmt":"2019-04-10T08:34:27","slug":"removal-of-implicit-and-explicit-sorting-for-group-by","status":"publish","type":"post","link":"https:\/\/jirak.net\/wp\/removal-of-implicit-and-explicit-sorting-for-group-by\/","title":{"rendered":"Removal of implicit and explicit sorting for GROUP BY"},"content":{"rendered":"<p>Removal of implicit and explicit sorting for GROUP BY<\/p>\n<p>In MySQL, historically GROUP BY was used to provide sorting as well. If a query specified GROUP BY, the result was sorted as if ORDER BY was present in the query.<\/p>\n<pre class=\"crayon-plain-tag\">mysql-5.7&gt; CREATE TABLE t (id INTEGER,  cnt INTEGER);\r\nQuery OK, 0 rows affected (0.03 sec)\r\n\r\nmysql-5.7&gt; INSERT INTO t VALUES (4,1),(3,2),(1,4),(2,2),(1,1),(1,5),(2,6),(2,1),(1,3),(3,4),(4,5),(3,6);\r\nQuery OK, 12 rows affected (0.02 sec)\r\nRecords: 12  Duplicates: 0  Warnings: 0\r\n\r\nmysql-5.7&gt; SELECT id, SUM(cnt) FROM t GROUP BY id;\r\n+------+----------+\r\n| id   | SUM(cnt) |\r\n+------+----------+\r\n|    1 |       13 |\r\n|    2 |        9 |\r\n|    3 |       12 |\r\n|    4 |        6 |\r\n+------+----------+\r\n4 rows in set (0.00 sec)<\/pre>\n<p>MySQL here implicitly sorts the results from GROUP BY (i.e.&hellip;<\/p>\n<div class=\"simplesocialbuttons simplesocial-sm-round simplesocialbuttons_inline simplesocialbuttons-align-left post-12325 post  simplesocialbuttons-inline-no-animation\">\n<button class=\"simplesocial-fb-share\" data-href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https:\/\/mysqlserverteam.com\/removal-of-implicit-and-explicit-sorting-for-group-by\/\"><span class=\"simplesocialtxt\">Facebook <\/span> <\/button><br \/>\n<button class=\"simplesocial-twt-share\" data-href=\"https:\/\/twitter.com\/share?text=Removal+of+implicit+and+explicit+sorting+for+GROUP+BY&amp;url=https:\/\/mysqlserverteam.com\/removal-of-implicit-and-explicit-sorting-for-group-by\/\"><span class=\"simplesocialtxt\">Twitter<\/span> <\/button><br \/>\n<button class=\"simplesocial-gplus-share\" data-href=\"https:\/\/plus.google.com\/share?url=https:\/\/mysqlserverteam.com\/removal-of-implicit-and-explicit-sorting-for-group-by\/\"><span class=\"simplesocialtxt\">Google+<\/span><\/button><br \/>\n<button class=\"simplesocial-linkedin-share\" data-href=\"https:\/\/www.linkedin.com\/cws\/share?url=https:\/\/mysqlserverteam.com\/removal-of-implicit-and-explicit-sorting-for-group-by\/\"><span class=\"simplesocialtxt\">LinkedIn<\/span><\/button>\n<\/div>\n<p>Source: <a href=\"https:\/\/mysqlserverteam.com\/removal-of-implicit-and-explicit-sorting-for-group-by\/\" target=\"_blank\" rel=\"noopener noreferrer\">Removal of implicit and explicit sorting for GROUP BY<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Removal of implicit and explicit sorting for GROUP BY In MySQL, historically GROUP BY was used to provide sorting as well. If a query specified GROUP BY, the result was sorted as if ORDER BY was present in the query. mysql-5.7&gt; CREATE TABLE t (id INTEGER, cnt INTEGER); Query OK, 0 rows affected (0.03 sec) mysql-5.7&gt; INSERT INTO t VALUES (4,1),(3,2),(1,4),(2,2),(1,1),(1,5),(2,6),(2,1),(1,3),(3,4),(4,5),(3,6); Query OK, 12 rows affected (0.02 sec) Records: 12 Duplicates: 0 Warnings: 0 mysql-5.7&gt; SELECT id, SUM(cnt) FROM t GROUP BY id; +&#8212;&#8212;+&#8212;&#8212;&#8212;-+ | id | SUM(cnt) | +&#8212;&#8212;+&#8212;&#8212;&#8212;-+ | 1 | 13 | | 2 | 9 | | 3 | 12 | | 4 | 6 | +&#8212;&#8212;+&#8212;&#8212;&#8212;-+ 4 rows in set (0.00 sec) MySQL here implicitly sorts the results from GROUP BY (i.e.&hellip; Facebook Twitter Google+ LinkedIn Source: Removal of implicit and explicit sorting for GROUP <a class=\"mh-excerpt-more\" href=\"https:\/\/jirak.net\/wp\/removal-of-implicit-and-explicit-sorting-for-group-by\/\" title=\"Removal of implicit and explicit sorting for GROUP BY\">[ more&#8230; ]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[498],"class_list":["post-30451","post","type-post","status-publish","format-standard","hentry","category-news","tag-mysql"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/30451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/comments?post=30451"}],"version-history":[{"count":1,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/30451\/revisions"}],"predecessor-version":[{"id":30452,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/30451\/revisions\/30452"}],"wp:attachment":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/media?parent=30451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/categories?post=30451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/tags?post=30451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}