{"id":63,"date":"2026-03-06T05:10:38","date_gmt":"2026-03-06T05:10:38","guid":{"rendered":"https:\/\/gigz.pk\/sql\/?post_type=lesson&#038;p=63"},"modified":"2026-03-16T18:48:14","modified_gmt":"2026-03-16T18:48:14","slug":"order-by","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/sql\/lesson\/order-by\/","title":{"rendered":"ORDER"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>ORDER BY<\/strong> is used in SQL to sort the result of a query. It arranges the data in ascending or descending order based on one or more columns.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When we retrieve data from a table, the records may appear in any order. If we want the data to appear in a specific order, we use <strong>ORDER BY<\/strong> in the query.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">SELECT column_name<br>FROM table_name<br>ORDER BY column_name ASC or DESC<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ASC<\/strong> means ascending order. In ascending order the data is arranged from smallest to largest. For example numbers from 1 to 100 or names from A to Z.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>DESC<\/strong> means descending order. In descending order the data is arranged from largest to smallest. For example numbers from 100 to 1 or names from Z to A.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">SELECT name<br>FROM students<br>ORDER BY name ASC<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This query will display the names of students in alphabetical order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Another Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">SELECT marks<br>FROM students<br>ORDER BY marks DESC<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This query will show the marks of students from highest to lowest.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using ORDER BY with Multiple Columns<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We can also sort data using more than one column.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SELECT name, marks<br>FROM students<br>ORDER BY marks DESC, name ASC<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this query, the data is first sorted by marks in descending order. If two students have the same marks, then their names are sorted in ascending order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ORDER BY<\/strong> helps organize the result of a query in a clear and meaningful way. It makes the data easier to read and analyze.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/sql\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">SQL Foundations Program (SQL-101) > Basic Queries > ORDER BY<\/span><\/span><\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":11,"template":"","class_list":["post-63","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ORDER - SQL Learning Hub<\/title>\n<meta name=\"description\" content=\"Learn SQL ORDER BY to sort query results in ascending or descending order. Includes syntax, examples, and sorting with multiple columns.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/sql\/lesson\/order-by\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ORDER - SQL Learning Hub\" \/>\n<meta property=\"og:description\" content=\"Learn SQL ORDER BY to sort query results in ascending or descending order. Includes syntax, examples, and sorting with multiple columns.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/sql\/lesson\/order-by\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Learning Hub\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-16T18:48:14+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/order-by\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/order-by\\\/\",\"name\":\"ORDER - SQL Learning Hub\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\"},\"datePublished\":\"2026-03-06T05:10:38+00:00\",\"dateModified\":\"2026-03-16T18:48:14+00:00\",\"description\":\"Learn SQL ORDER BY to sort query results in ascending or descending order. Includes syntax, examples, and sorting with multiple columns.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/order-by\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/order-by\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/order-by\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Foundations Program (SQL-101) > Basic Queries > ORDER BY\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/\",\"name\":\"SQL Learning Hub\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ORDER - SQL Learning Hub","description":"Learn SQL ORDER BY to sort query results in ascending or descending order. Includes syntax, examples, and sorting with multiple columns.","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:\/\/gigz.pk\/sql\/lesson\/order-by\/","og_locale":"en_US","og_type":"article","og_title":"ORDER - SQL Learning Hub","og_description":"Learn SQL ORDER BY to sort query results in ascending or descending order. Includes syntax, examples, and sorting with multiple columns.","og_url":"https:\/\/gigz.pk\/sql\/lesson\/order-by\/","og_site_name":"SQL Learning Hub","article_modified_time":"2026-03-16T18:48:14+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/gigz.pk\/sql\/lesson\/order-by\/","url":"https:\/\/gigz.pk\/sql\/lesson\/order-by\/","name":"ORDER - SQL Learning Hub","isPartOf":{"@id":"https:\/\/gigz.pk\/sql\/#website"},"datePublished":"2026-03-06T05:10:38+00:00","dateModified":"2026-03-16T18:48:14+00:00","description":"Learn SQL ORDER BY to sort query results in ascending or descending order. Includes syntax, examples, and sorting with multiple columns.","breadcrumb":{"@id":"https:\/\/gigz.pk\/sql\/lesson\/order-by\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/sql\/lesson\/order-by\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/sql\/lesson\/order-by\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/sql\/"},{"@type":"ListItem","position":2,"name":"SQL Foundations Program (SQL-101) > Basic Queries > ORDER BY"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/sql\/#website","url":"https:\/\/gigz.pk\/sql\/","name":"SQL Learning Hub","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/sql\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/lesson\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/sql\/wp-json\/wp\/v2\/media?parent=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}