{"id":64,"date":"2026-03-06T05:13:02","date_gmt":"2026-03-06T05:13:02","guid":{"rendered":"https:\/\/gigz.pk\/sql\/?post_type=lesson&#038;p=64"},"modified":"2026-03-16T18:48:23","modified_gmt":"2026-03-16T18:48:23","slug":"limit-top","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/sql\/lesson\/limit-top\/","title":{"rendered":"\u00a0LIMIT \/ TOP"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">LIMIT and TOP are used in databases to restrict the number of records returned in a query result. They help when we only need a specific number of rows instead of the complete data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TOP<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">TOP is mostly used in Microsoft SQL Server and MS Access. It returns the first specified number of records from a table.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<br>SELECT TOP 5 * FROM Students<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This query will display only the first 5 records from the Students table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TOP with ORDER BY<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">TOP is often used with ORDER BY to get the highest or lowest values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<br>SELECT TOP 3 Name, Marks FROM Students<br>ORDER BY Marks DESC<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This query shows the top 3 students with the highest marks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>LIMIT<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">LIMIT is used in MySQL and PostgreSQL to control how many records are returned.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<br>SELECT * FROM Students<br>LIMIT 5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This query will return only 5 records from the Students table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>LIMIT with ORDER BY<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">LIMIT can also be used with ORDER BY to get specific results.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<br>SELECT Name, Marks FROM Students<br>ORDER BY Marks DESC<br>LIMIT 3<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This query will display the 3 students with the highest marks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Difference between LIMIT and TOP<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">TOP is used in SQL Server.<br>LIMIT is used in MySQL and PostgreSQL.<br>Both are used to restrict the number of records returned by a query.<\/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 > LIMIT \/ TOP<\/span><\/span><\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":12,"template":"","class_list":["post-64","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>\u00a0LIMIT \/ TOP - SQL Learning Hub<\/title>\n<meta name=\"description\" content=\"Learn how to use SQL LIMIT and TOP to control query results. Understand differences, examples, and usage in MySQL, PostgreSQL, and SQL Server.\" \/>\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\/limit-top\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u00a0LIMIT \/ TOP - SQL Learning Hub\" \/>\n<meta property=\"og:description\" content=\"Learn how to use SQL LIMIT and TOP to control query results. Understand differences, examples, and usage in MySQL, PostgreSQL, and SQL Server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/sql\/lesson\/limit-top\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Learning Hub\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-16T18:48:23+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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/limit-top\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/limit-top\\\/\",\"name\":\"\u00a0LIMIT \\\/ TOP - SQL Learning Hub\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\"},\"datePublished\":\"2026-03-06T05:13:02+00:00\",\"dateModified\":\"2026-03-16T18:48:23+00:00\",\"description\":\"Learn how to use SQL LIMIT and TOP to control query results. Understand differences, examples, and usage in MySQL, PostgreSQL, and SQL Server.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/limit-top\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/limit-top\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/limit-top\\\/#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 > LIMIT \\\/ TOP\"}]},{\"@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":"\u00a0LIMIT \/ TOP - SQL Learning Hub","description":"Learn how to use SQL LIMIT and TOP to control query results. Understand differences, examples, and usage in MySQL, PostgreSQL, and SQL Server.","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\/limit-top\/","og_locale":"en_US","og_type":"article","og_title":"\u00a0LIMIT \/ TOP - SQL Learning Hub","og_description":"Learn how to use SQL LIMIT and TOP to control query results. Understand differences, examples, and usage in MySQL, PostgreSQL, and SQL Server.","og_url":"https:\/\/gigz.pk\/sql\/lesson\/limit-top\/","og_site_name":"SQL Learning Hub","article_modified_time":"2026-03-16T18:48:23+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/gigz.pk\/sql\/lesson\/limit-top\/","url":"https:\/\/gigz.pk\/sql\/lesson\/limit-top\/","name":"\u00a0LIMIT \/ TOP - SQL Learning Hub","isPartOf":{"@id":"https:\/\/gigz.pk\/sql\/#website"},"datePublished":"2026-03-06T05:13:02+00:00","dateModified":"2026-03-16T18:48:23+00:00","description":"Learn how to use SQL LIMIT and TOP to control query results. Understand differences, examples, and usage in MySQL, PostgreSQL, and SQL Server.","breadcrumb":{"@id":"https:\/\/gigz.pk\/sql\/lesson\/limit-top\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/sql\/lesson\/limit-top\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/sql\/lesson\/limit-top\/#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 > LIMIT \/ TOP"}]},{"@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\/64","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=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}