{"id":171,"date":"2018-12-06T10:49:04","date_gmt":"2018-12-06T10:49:04","guid":{"rendered":"https:\/\/barkhane.com\/sql\/2018\/12\/06\/sql-select-query\/"},"modified":"2024-03-03T17:59:23","modified_gmt":"2024-03-03T17:59:23","slug":"sql-select-query","status":"publish","type":"post","link":"https:\/\/barkhane.com\/sql\/sql-select-query\/","title":{"rendered":"SQL SELECT Query"},"content":{"rendered":"<p>SQL SELECT Query is the most commonly used statement in SQL. The SELECT Statement in SQL is used to retrieve or fetch data from a database. We can fetch either the entire table or according to some specified rules. The data returned is stored in a result table. This result table is also called result-set.<\/p>\n<p>With the SELECT clause of a SELECT command statement, we specify the columns that we want to be displayed in the query result and, optionally, which column headings we prefer to see above the result table.<\/p>\n<p>The select clause is the first clause and is one of the last clauses of the select statement that the database server evaluates. The reason for this is that before we can determine what to include in the final result set, we need to know all of the possible columns that could be included in the final result set.<\/p>\n<p><strong>Sample Table:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<table>\n<thead>\n<tr>\n<td><strong>ROLL_NO<\/strong><\/td>\n<td><strong>NAME<\/strong><\/td>\n<td><strong>ADDRESS<\/strong><\/td>\n<td><strong>PHONE<\/strong><\/td>\n<td><strong>Age<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>Gopal<\/td>\n<td>Goa<\/td>\n<td>8965123451<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>golu<\/td>\n<td>Mumbai<\/td>\n<td>9411111451<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Mukesh<\/td>\n<td>Indore<\/td>\n<td>9987456321<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Pramesh<\/td>\n<td>Goa<\/td>\n<td>8166253142<\/td>\n<td>18<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Basic Syntax:<\/strong><\/p>\n<pre><strong>SELECT column1,column2 FROM table_name <\/strong>  <strong>column1 , column2<\/strong>: names of the fields of the table  <strong>table_name:<\/strong> from where we want to fetch<\/pre>\n<p>This query will return all the rows in the table with fields column1 , column2.<\/p>\n<ul>\n<li>To fetch the entire table or all the fields in the table:\n<pre> SELECT * FROM table_name;<\/pre>\n<\/li>\n<li>Query to fetch the fields ROLL_NO, NAME, AGE from the table Student:\n<pre>SELECT ROLL_NO, NAME, AGE FROM Student;<\/pre>\n<p>Output:<\/p>\n<table>\n<thead>\n<tr>\n<td><strong>ROLL_NO<\/strong><\/td>\n<td><strong>NAME<\/strong><\/td>\n<td><strong>Age<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>Gopal<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>golu<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Mukesh<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Pramesh<\/td>\n<td>18<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<li>To fetch all the fields from the table Student:\n<pre> SELECT * FROM Student;<\/pre>\n<p>Output:<\/p>\n<table>\n<thead>\n<tr>\n<td><strong>ROLL_NO<\/strong><\/td>\n<td><strong>NAME<\/strong><\/td>\n<td><strong>ADDRESS<\/strong><\/td>\n<td><strong>PHONE<\/strong><\/td>\n<td><strong>Age<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>Gopal<\/td>\n<td>Goa<\/td>\n<td>8965123451<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>golu<\/td>\n<td>Mumbai<\/td>\n<td>9411111451<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Mukesh<\/td>\n<td>Indore<\/td>\n<td>9987456321<\/td>\n<td>20<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Pramesh<\/td>\n<td>Goa<\/td>\n<td>8166253142<\/td>\n<td>18<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL SELECT Query is the most commonly used statement in SQL. The SELECT Statement in SQL is used to retrieve [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}