{"id":60,"date":"2026-03-05T11:08:42","date_gmt":"2026-03-05T11:08:42","guid":{"rendered":"https:\/\/gigz.pk\/sql\/?post_type=lesson&#038;p=60"},"modified":"2026-03-16T18:47:49","modified_gmt":"2026-03-16T18:47:49","slug":"select-statement","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/sql\/lesson\/select-statement\/","title":{"rendered":"\u00a0SELECT Statement"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">he <strong>SELECT<\/strong> statement is one of the most fundamental commands in SQL. It is used to retrieve data from a database. By using SELECT, you can specify exactly which data you want to view and how it should be presented.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The basic syntax of a SELECT statement is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT column1, column2, ...<br>FROM table_name;<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SELECT<\/strong> \u2013 specifies the columns you want to retrieve.<\/li>\n\n\n\n<li><strong>FROM<\/strong> \u2013 specifies the table from which to retrieve the data.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT first_name, last_name<br>FROM employees;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This query retrieves the <code>first_name<\/code> and <code>last_name<\/code> columns from the <code>employees<\/code> table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Selecting All Columns<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To retrieve all columns from a table, use the asterisk (*):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT *<br>FROM employees;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will return every column in the <code>employees<\/code> table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using WHERE Clause<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>WHERE<\/strong> clause allows you to filter records based on specific conditions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT first_name, last_name<br>FROM employees<br>WHERE department = 'Sales';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This query retrieves only the employees who work in the Sales department.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using DISTINCT<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>DISTINCT<\/strong> keyword ensures that the query returns unique values only.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT DISTINCT department<br>FROM employees;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This query lists all the unique departments in the <code>employees<\/code> table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using ORDER BY<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>ORDER BY<\/strong> clause sorts the result set by one or more columns.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT first_name, last_name<br>FROM employees<br>ORDER BY last_name ASC;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This query retrieves employees&#8217; names sorted alphabetically by <code>last_name<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using LIMIT<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>LIMIT<\/strong> clause restricts the number of rows returned.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT first_name, last_name<br>FROM employees<br>LIMIT 5;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This query retrieves only the first five rows from the <code>employees<\/code> table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>SELECT<\/strong> is used to fetch data from a database.<\/li>\n\n\n\n<li>Columns can be specified individually or with <code>*<\/code> for all columns.<\/li>\n\n\n\n<li>Filters can be applied using <strong>WHERE<\/strong>.<\/li>\n\n\n\n<li>Unique values can be retrieved using <strong>DISTINCT<\/strong>.<\/li>\n\n\n\n<li>Results can be sorted using <strong>ORDER BY<\/strong>.<\/li>\n\n\n\n<li>Limit the number of results using <strong>LIMIT<\/strong>.<\/li>\n<\/ul>\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 > SELECT Statement<\/span><\/span><\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":8,"template":"","class_list":["post-60","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>\u00a0SELECT Statement - SQL Learning Hub<\/title>\n<meta name=\"description\" content=\"Learn the SQL SELECT statement with examples. Discover how to retrieve, filter, sort, and limit database data using simple SQL queries.\" \/>\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\/select-statement\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u00a0SELECT Statement - SQL Learning Hub\" \/>\n<meta property=\"og:description\" content=\"Learn the SQL SELECT statement with examples. Discover how to retrieve, filter, sort, and limit database data using simple SQL queries.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/sql\/lesson\/select-statement\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Learning Hub\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-16T18:47:49+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\\\/select-statement\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/select-statement\\\/\",\"name\":\"\u00a0SELECT Statement - SQL Learning Hub\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/#website\"},\"datePublished\":\"2026-03-05T11:08:42+00:00\",\"dateModified\":\"2026-03-16T18:47:49+00:00\",\"description\":\"Learn the SQL SELECT statement with examples. Discover how to retrieve, filter, sort, and limit database data using simple SQL queries.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/select-statement\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/select-statement\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/sql\\\/lesson\\\/select-statement\\\/#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 > SELECT Statement\"}]},{\"@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":"\u00a0SELECT Statement - SQL Learning Hub","description":"Learn the SQL SELECT statement with examples. Discover how to retrieve, filter, sort, and limit database data using simple SQL queries.","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\/select-statement\/","og_locale":"en_US","og_type":"article","og_title":"\u00a0SELECT Statement - SQL Learning Hub","og_description":"Learn the SQL SELECT statement with examples. Discover how to retrieve, filter, sort, and limit database data using simple SQL queries.","og_url":"https:\/\/gigz.pk\/sql\/lesson\/select-statement\/","og_site_name":"SQL Learning Hub","article_modified_time":"2026-03-16T18:47:49+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\/select-statement\/","url":"https:\/\/gigz.pk\/sql\/lesson\/select-statement\/","name":"\u00a0SELECT Statement - SQL Learning Hub","isPartOf":{"@id":"https:\/\/gigz.pk\/sql\/#website"},"datePublished":"2026-03-05T11:08:42+00:00","dateModified":"2026-03-16T18:47:49+00:00","description":"Learn the SQL SELECT statement with examples. Discover how to retrieve, filter, sort, and limit database data using simple SQL queries.","breadcrumb":{"@id":"https:\/\/gigz.pk\/sql\/lesson\/select-statement\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/sql\/lesson\/select-statement\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/sql\/lesson\/select-statement\/#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 > SELECT Statement"}]},{"@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\/60","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=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}