{"id":3557,"date":"2023-04-12T15:39:28","date_gmt":"2023-04-12T15:39:28","guid":{"rendered":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/"},"modified":"2026-01-15T18:19:38","modified_gmt":"2026-01-15T18:19:38","slug":"basic-sql-functions-part-4-order-by-statement","status":"publish","type":"post","link":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/","title":{"rendered":"How Do I Use the SQL ORDER BY Statement to Sort Query Results?"},"content":{"rendered":"<p>Similar to the GROUP BY clause, the ORDER BY clause also determines how the data is displayed in the view and not so much what the view is displaying. The ORDER BY clause controls the order in which records appear in a view. The order can be determined by the numerical magnitude if it is a numerical data type, or the alphabetical order if it is a char data type.<\/p>\n<p>There is also a functionality to ORDER BY that allows the user to determine if they want the records to show in ascending order or descending order. By default, if we say <strong><em>ORDER BY total_amount<\/em><\/strong>, this will order the view by the total amount spent in <strong>ascending <\/strong>order. If we would like to specify that we want the total amount spent to be ordered by descending order we would specify that in the statement, <strong><em>ORDER BY total_amount desc<\/em><\/strong>, tacking on desc at the end of the order by will accomplish this.<\/p>\n<p>The ORDER BY clause is placed after the GROUP BY clause.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-1045 aligncenter\" src=\"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2020\/06\/Part5A-min-188x300.jpg\" alt=\"\" width=\"188\" height=\"300\" \/><\/p>\n<p>Click here for <a href=\"https:\/\/quebit.com\/askquebit\/quebit-products\/basic-sql-functions-part-5-joins\/\">Part 5: JOINS<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Similar to the GROUP BY clause, the ORDER BY clause also determines how the data is displayed in the view and not so much what the view is displaying. The ORDER BY clause controls the order in which records appear in a view. The order can be determined by the numerical magnitude if it is&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[27],"tags":[32],"class_list":["post-3557","post","type-post","status-publish","format-standard","hentry","category-quebit-value","tag-sql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How Do I Use the SQL ORDER BY Statement to Sort Query Results? - QueBIT<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How Do I Use the SQL ORDER BY Statement to Sort Query Results? - QueBIT\" \/>\n<meta property=\"og:description\" content=\"Similar to the GROUP BY clause, the ORDER BY clause also determines how the data is displayed in the view and not so much what the view is displaying. The ORDER BY clause controls the order in which records appear in a view. The order can be determined by the numerical magnitude if it is&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/\" \/>\n<meta property=\"og:site_name\" content=\"QueBIT\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-12T15:39:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-15T18:19:38+00:00\" \/>\n<meta name=\"author\" content=\"agoddard\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"agoddard\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/\"},\"author\":{\"name\":\"agoddard\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#\\\/schema\\\/person\\\/e52d72da0fd2f5f70d189343fe4f5084\"},\"headline\":\"How Do I Use the SQL ORDER BY Statement to Sort Query Results?\",\"datePublished\":\"2023-04-12T15:39:28+00:00\",\"dateModified\":\"2026-01-15T18:19:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/\"},\"wordCount\":192,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Part5A-min-188x300.jpg\",\"keywords\":[\"SQL\"],\"articleSection\":[\"QueBIT Value\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/\",\"url\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/\",\"name\":\"How Do I Use the SQL ORDER BY Statement to Sort Query Results? - QueBIT\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Part5A-min-188x300.jpg\",\"datePublished\":\"2023-04-12T15:39:28+00:00\",\"dateModified\":\"2026-01-15T18:19:38+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#\\\/schema\\\/person\\\/e52d72da0fd2f5f70d189343fe4f5084\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/#primaryimage\",\"url\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Part5A-min-188x300.jpg\",\"contentUrl\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Part5A-min-188x300.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/basic-sql-functions-part-4-order-by-statement\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How Do I Use the SQL ORDER BY Statement to Sort Query Results?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#website\",\"url\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/\",\"name\":\"QueBIT\",\"description\":\"QueBIT\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/#\\\/schema\\\/person\\\/e52d72da0fd2f5f70d189343fe4f5084\",\"name\":\"agoddard\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g\",\"caption\":\"agoddard\"},\"sameAs\":[\"https:\\\/\\\/quebit.com\\\/askquebit\"],\"url\":\"https:\\\/\\\/quebit.com\\\/askquebit\\\/author\\\/agoddard\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How Do I Use the SQL ORDER BY Statement to Sort Query Results? - QueBIT","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/","og_locale":"en_US","og_type":"article","og_title":"How Do I Use the SQL ORDER BY Statement to Sort Query Results? - QueBIT","og_description":"Similar to the GROUP BY clause, the ORDER BY clause also determines how the data is displayed in the view and not so much what the view is displaying. The ORDER BY clause controls the order in which records appear in a view. The order can be determined by the numerical magnitude if it is&hellip;","og_url":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/","og_site_name":"QueBIT","article_published_time":"2023-04-12T15:39:28+00:00","article_modified_time":"2026-01-15T18:19:38+00:00","author":"agoddard","twitter_card":"summary_large_image","twitter_misc":{"Written by":"agoddard","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/#article","isPartOf":{"@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/"},"author":{"name":"agoddard","@id":"https:\/\/quebit.com\/askquebit\/#\/schema\/person\/e52d72da0fd2f5f70d189343fe4f5084"},"headline":"How Do I Use the SQL ORDER BY Statement to Sort Query Results?","datePublished":"2023-04-12T15:39:28+00:00","dateModified":"2026-01-15T18:19:38+00:00","mainEntityOfPage":{"@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/"},"wordCount":192,"commentCount":0,"image":{"@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/#primaryimage"},"thumbnailUrl":"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2020\/06\/Part5A-min-188x300.jpg","keywords":["SQL"],"articleSection":["QueBIT Value"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/","url":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/","name":"How Do I Use the SQL ORDER BY Statement to Sort Query Results? - QueBIT","isPartOf":{"@id":"https:\/\/quebit.com\/askquebit\/#website"},"primaryImageOfPage":{"@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/#primaryimage"},"image":{"@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/#primaryimage"},"thumbnailUrl":"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2020\/06\/Part5A-min-188x300.jpg","datePublished":"2023-04-12T15:39:28+00:00","dateModified":"2026-01-15T18:19:38+00:00","author":{"@id":"https:\/\/quebit.com\/askquebit\/#\/schema\/person\/e52d72da0fd2f5f70d189343fe4f5084"},"breadcrumb":{"@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/#primaryimage","url":"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2020\/06\/Part5A-min-188x300.jpg","contentUrl":"https:\/\/quebit.com\/askquebit\/wp-content\/uploads\/2020\/06\/Part5A-min-188x300.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/quebit.com\/askquebit\/basic-sql-functions-part-4-order-by-statement\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/quebit.com\/askquebit\/"},{"@type":"ListItem","position":2,"name":"How Do I Use the SQL ORDER BY Statement to Sort Query Results?"}]},{"@type":"WebSite","@id":"https:\/\/quebit.com\/askquebit\/#website","url":"https:\/\/quebit.com\/askquebit\/","name":"QueBIT","description":"QueBIT","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/quebit.com\/askquebit\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/quebit.com\/askquebit\/#\/schema\/person\/e52d72da0fd2f5f70d189343fe4f5084","name":"agoddard","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d817b364cff1d66116debde8d1c85e5e76eeece9c5ae731b19276a6040231455?s=96&d=mm&r=g","caption":"agoddard"},"sameAs":["https:\/\/quebit.com\/askquebit"],"url":"https:\/\/quebit.com\/askquebit\/author\/agoddard\/"}]}},"_links":{"self":[{"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/posts\/3557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/comments?post=3557"}],"version-history":[{"count":1,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/posts\/3557\/revisions"}],"predecessor-version":[{"id":4922,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/posts\/3557\/revisions\/4922"}],"wp:attachment":[{"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/media?parent=3557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/categories?post=3557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/quebit.com\/askquebit\/wp-json\/wp\/v2\/tags?post=3557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}