{"id":4457,"date":"2018-03-30T15:35:56","date_gmt":"2018-03-30T15:35:56","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2018\/03\/30\/how-to-write-select-statements\/"},"modified":"2021-10-26T14:12:58","modified_gmt":"2021-10-26T18:12:58","slug":"how-to-write-select-statements","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/","title":{"rendered":"How to Write Select Statements"},"content":{"rendered":"\n<p>The <em>Select<\/em> statement is a very simple but important part of SQL. At this point, if you read the <a href=\"\/support\/server\/databases\/what-is-sql\/\">What is SQL?<\/a> article, I presume you have a bunch of test data to work with. The important thing about data is not always the data itself but what insights you can draw from the data. The <em>Select<\/em> statement will help you comb through that data so you find what you&#8217;re looking for.<\/p>\n\n\n\n<p>If you&#8217;re looking for a dedicated database solution, find out about getting yourself a <a href=\"https:\/\/www.inmotionhosting.com\/managed-dedicated-servers\">dedicated managed server<\/a> with build-in SQL suppot.<\/p>\n\n\n\n<p>You may recall, in the <em>What is SQL?<\/em> article, we mentioned <em>creating, reading, writing<\/em>, and <em>deleting<\/em> as fundamental SQL actions. Using <em>Select<\/em> statements will allow you to accomplish the &#8220;reading&#8221; action, so you can display your data in different ways, such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A list blog posts<\/li><li>A group of customers<\/li><li>A bunch of cities<\/li><\/ul>\n\n\n\n<p>No matter what kind of data you&#8217;ve collected, <em>Select<\/em> statements will help you sort it and read it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Selecting *All* Newsletter Respondents<\/h2>\n\n\n\n<p>Imagine you had a signup form on your website. Visitors provide their name and email. And the form itself grabs their IP address.<\/p>\n\n\n\n<p>Your database may hold this information in a table called &#8220;respondents&#8221;. Each respondent will have a unique identification number. So that amounts to five columns in your table:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>id<\/li><li>first name<\/li><li>last name<\/li><li>email<\/li><li>IP address<\/li><\/ol>\n\n\n\n<p>For our first example, let&#8217;s say you just want to see <em>all<\/em> respondents. We can select all respondents using an <code>*<\/code> in our statement:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted code_block\"><span style=\"color: blue;\">SELECT<\/span> * <span style=\"color: blue;\">FROM<\/span> <em>respondents<\/em>;<\/pre>\n\n\n\n<p>&#8220;Respondents&#8221; being the name of our table.<\/p>\n\n\n\n<p>Make note of the syntax here. The SQL statement parts are capitalized, but this is not required. And a semi-color <code>;<\/code> ends the statement.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Select Less Data<\/h2>\n\n\n\n<p>Often, it&#8217;s beneficial to be more <em>selective<\/em> with our <em>Select<\/em> statements. In the following example, let&#8217;s suppose you only want to see the names of our respondents. You could use the following statement:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted code_block\"><span style=\"color: blue;\">SELECT<\/span> \"first_name\", \"last_name\" <span style=\"color: blue;\">FROM<\/span> <em>respondents<\/em>;<\/pre>\n\n\n\n<p>This will produce the first and last name records for all of our respondents.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summing Up<\/h2>\n\n\n\n<p>You can now see the basic syntax for <em>Select<\/em> statements in SQL. This is only an introduction. These statements can grow quickly in complexity. However, the basic syntax for selecting information from your database remains the same. As your need for more complicated records grows, your statements will get larger and more complex. Stay tuned in our SQL series, as we move on to discuss creating and deleting tables in our database.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Select statement is a very simple but important part of SQL. At this point, if you read the What is SQL? article, I presume you have a bunch of test data to work with. The important thing about data is not always the data itself but what insights you can draw from the data.<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/\"> Read More ><\/a><\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4305],"tags":[],"class_list":["post-4457","post","type-post","status-publish","format-standard","hentry","category-databases"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Write Select Statements | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"In this article, you&#039;ll learn how to write Select statements.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Write Select Statements | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"In this article, you&#039;ll learn how to write Select statements.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-30T15:35:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-26T18:12:58+00:00\" \/>\n<meta name=\"author\" content=\"Christopher Maiorana\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christopher Maiorana\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/\"},\"author\":{\"name\":\"Christopher Maiorana\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f\"},\"headline\":\"How to Write Select Statements\",\"datePublished\":\"2018-03-30T15:35:56+00:00\",\"dateModified\":\"2021-10-26T18:12:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/\"},\"wordCount\":416,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"Working with Databases\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/\",\"name\":\"How to Write Select Statements | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2018-03-30T15:35:56+00:00\",\"dateModified\":\"2021-10-26T18:12:58+00:00\",\"description\":\"In this article, you'll learn how to write Select statements.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Write Select Statements\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f\",\"name\":\"Christopher Maiorana\",\"description\":\"Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/chris-m-4623144b\/\"],\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/christopherm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Write Select Statements | InMotion Hosting","description":"In this article, you'll learn how to write Select statements.","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:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/","og_locale":"en_US","og_type":"article","og_title":"How to Write Select Statements | InMotion Hosting","og_description":"In this article, you'll learn how to write Select statements.","og_url":"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2018-03-30T15:35:56+00:00","article_modified_time":"2021-10-26T18:12:58+00:00","author":"Christopher Maiorana","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Christopher Maiorana","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/"},"author":{"name":"Christopher Maiorana","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f"},"headline":"How to Write Select Statements","datePublished":"2018-03-30T15:35:56+00:00","dateModified":"2021-10-26T18:12:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/"},"wordCount":416,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["Working with Databases"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/","url":"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/","name":"How to Write Select Statements | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2018-03-30T15:35:56+00:00","dateModified":"2021-10-26T18:12:58+00:00","description":"In this article, you'll learn how to write Select statements.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/databases\/how-to-write-select-statements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to Write Select Statements"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f","name":"Christopher Maiorana","description":"Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.","sameAs":["https:\/\/www.linkedin.com\/in\/chris-m-4623144b\/"],"url":"https:\/\/www.inmotionhosting.com\/support\/author\/christopherm\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/4457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=4457"}],"version-history":[{"count":5,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/4457\/revisions"}],"predecessor-version":[{"id":90316,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/4457\/revisions\/90316"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=4457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=4457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=4457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}