{"id":7353,"date":"2019-10-21T09:26:55","date_gmt":"2019-10-21T09:26:55","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=7353"},"modified":"2019-10-28T06:24:29","modified_gmt":"2019-10-28T06:24:29","slug":"what-is-the-best-way-to-learn-sql-for-data-analyst","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/what-is-the-best-way-to-learn-sql-for-data-analyst\/","title":{"rendered":"What is the best way to learn SQL for data analyst?"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Fundamental SQL Statements<\/h3>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Create<\/strong>: creating a basic table involves naming the table and defining its columns and each column&#8217;s data type.<br><strong>Syntax<\/strong> : <br>CREATE TABLE &#8220;table_name&#8221;(<br> &#8220;column 1&#8221;    &#8220;data type for column 1&#8221;    [column 1 constraint(s)],<br> &#8220;column 2&#8221;    &#8220;data type for column 2&#8221;    [column 2 constraint(s)], <br>&#8230;&#8230;<br>&#8220;column n&#8221;<br>[&#8220;table constraint(s)&#8221;]);<br><\/li><\/ol>\n\n\n\n<p><strong>Example : <\/strong><br>create table Engineer_table (<br> Cust_id int,<br> First_name varchar,<br> Last_name varchar,<br> age int,<br> email_id varchar);<br> )<\/p>\n\n\n\n<p>Constraints define the type of data which will be entered into the table column. <br>Now  I am defining the type of Constraints, so please look below for a better understanding of constraints:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>NOT NULL<\/strong> <strong>Constraint<\/strong>: Ensures that a column cannot have NULL value.<\/li><li><strong>DEFAULT Constraint<\/strong>: Provides a default value for a column when none is specified.<\/li><li><strong>UNIQUE Constraint<\/strong>: Ensures that all values in a column are different.<\/li><li><strong>CHECK Constraint<\/strong>: Makes sure that all values in a column satisfy certain criteria.<\/li><li><strong>Primary Key Constraint<\/strong>: Used to uniquely identify a row in the table.<\/li><li><strong>Foreign Key Constraint<\/strong>: used to ensure referential integrity of the data.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Keys<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>A primary key is used to uniquely identify each row in a table and consist of one or more columns on a table.<\/li><li>When multiple columns are used as a primary key, they are called a composite key.<\/li><li>A foreign key is a column( or columns) that references a column (most often the primary key) of another table.<\/li><\/ul>\n\n\n\n<p>2. <strong><em>INSERT<\/em><\/strong>: The INSERT INTO statement is used to add new records into a database table.<\/p>\n\n\n\n<p><strong>Syntax<\/strong>: <br>INSERT INTO &#8220;table_name&#8221; (&#8220;column1&#8243;,&#8221;column2&#8221;,\u2026) VALUES(&#8220;value1&#8243;,&#8221;value2&#8221;,\u2026);<\/p>\n\n\n\n<p>Example:<br><strong>Single row<\/strong> (<em>without column names specified<\/em>)<br>      INSERT INTO customer_table<br>      VALUES(1, &#8216;chandan&#8217;,&#8217;Kumar&#8217;,23,&#8217;chandan@devopsschool.com&#8217;); <br><br><strong>Single row<\/strong> (<em>with column name specified<\/em>)<br>      INSERT INTO customer_table(cust_id,first_name,last_name,age,email_id)<br>      VALUES(2, &#8216;Ajay&#8217;,&#8217;Kumar&#8217;,24,&#8217;ajay@devopsschool.com&#8217;);  <br><br><strong><em>Multiple rows<\/em><\/strong><br>INSERT INTO customer_table<br>VALUES (1,&#8217;ck&#8217;,&#8217;dk&#8217;,35,&#8217;az@xyz.com&#8217;),<br>(2,&#8217;ak&#8217;,&#8217;pj&#8217;,36,&#8217;hg@xyz.com&#8217;);<\/p>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fundamental SQL Statements Create: creating a basic table involves naming the table and defining its columns and each column&#8217;s data type.Syntax : CREATE TABLE &#8220;table_name&#8221;( &#8220;column 1&#8221; &#8220;data type for&#8230; <\/p>\n","protected":false},"author":8,"featured_media":7463,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5150],"tags":[5445,5448,5446,421,5447,3242],"class_list":["post-7353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","tag-fundamental","tag-insert","tag-query","tag-sql","tag-table","tag-unique"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/7353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=7353"}],"version-history":[{"count":5,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/7353\/revisions"}],"predecessor-version":[{"id":7375,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/7353\/revisions\/7375"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/7463"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=7353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=7353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=7353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}