{"id":248190,"date":"2022-09-07T08:44:33","date_gmt":"2022-09-07T08:44:33","guid":{"rendered":"https:\/\/imarticus.org\/?p=248190"},"modified":"2024-03-29T09:50:58","modified_gmt":"2024-03-29T09:50:58","slug":"top-11-sql-queries-that-a-data-scientist-should-know","status":"publish","type":"post","link":"https:\/\/imarticus.org\/blog\/top-11-sql-queries-that-a-data-scientist-should-know\/","title":{"rendered":"Top 11 SQL queries that a data scientist should know"},"content":{"rendered":"<h1><span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Top 11 SQL queries that a data scientist should know&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:12476,&quot;5&quot;:{&quot;1&quot;:[{&quot;1&quot;:2,&quot;2&quot;:0,&quot;5&quot;:{&quot;1&quot;:2,&quot;2&quot;:0}},{&quot;1&quot;:0,&quot;2&quot;:0,&quot;3&quot;:3},{&quot;1&quot;:1,&quot;2&quot;:0,&quot;4&quot;:1}]},&quot;6&quot;:{&quot;1&quot;:[{&quot;1&quot;:2,&quot;2&quot;:0,&quot;5&quot;:{&quot;1&quot;:2,&quot;2&quot;:0}},{&quot;1&quot;:0,&quot;2&quot;:0,&quot;3&quot;:3},{&quot;1&quot;:1,&quot;2&quot;:0,&quot;4&quot;:1}]},&quot;7&quot;:{&quot;1&quot;:[{&quot;1&quot;:2,&quot;2&quot;:0,&quot;5&quot;:{&quot;1&quot;:2,&quot;2&quot;:0}},{&quot;1&quot;:0,&quot;2&quot;:0,&quot;3&quot;:3},{&quot;1&quot;:1,&quot;2&quot;:0,&quot;4&quot;:1}]},&quot;8&quot;:{&quot;1&quot;:[{&quot;1&quot;:2,&quot;2&quot;:0,&quot;5&quot;:{&quot;1&quot;:2,&quot;2&quot;:0}},{&quot;1&quot;:0,&quot;2&quot;:0,&quot;3&quot;:3},{&quot;1&quot;:1,&quot;2&quot;:0,&quot;4&quot;:1}]},&quot;10&quot;:2,&quot;15&quot;:&quot;Calibri&quot;,&quot;16&quot;:12}\">Top 11 SQL queries that a data scientist should know<\/span><\/h1>\n<p><span style=\"font-weight: 400;\">A relational database management system uses SQL for managing data and for storing it in tabular form. SQL stands for Structured Query Language and it is a query language that is extremely useful for data scientists. <\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright wp-image-246113 size-medium\" src=\"https:\/\/imarticus.org\/blog\/wp-content\/uploads\/2021\/12\/rhrh-300x169.jpg\" alt=\"best data analytics course\" width=\"300\" height=\"169\" srcset=\"https:\/\/imarticus.org\/blog\/wp-content\/uploads\/2021\/12\/rhrh-300x169.jpg 300w, https:\/\/imarticus.org\/blog\/wp-content\/uploads\/2021\/12\/rhrh-1024x576.jpg 1024w, https:\/\/imarticus.org\/blog\/wp-content\/uploads\/2021\/12\/rhrh-768x432.jpg 768w, https:\/\/imarticus.org\/blog\/wp-content\/uploads\/2021\/12\/rhrh-1536x864.jpg 1536w, https:\/\/imarticus.org\/blog\/wp-content\/uploads\/2021\/12\/rhrh.jpg 1920w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">If you want to <\/span><strong><a href=\"https:\/\/imarticus.org\/postgraduate-program-in-data-science-analytics\/\">learn data analytics<\/a><\/strong><span style=\"font-weight: 400;\"> and get a <\/span><strong><a href=\"https:\/\/imarticus.org\/postgraduate-program-in-data-science-analytics\/\">data science certification course<\/a><\/strong><span style=\"font-weight: 400;\"> done for your progressive career, SQL is absolutely essential. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here are some essential SQL queries for data scientists. Data scientists need to be able to retrieve and store the data which you have derived without the help of others.<\/span><\/p>\n<h2><strong>Must know SQL queries for a data scientist<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">A data scientist must know the following basic queries to store and manage data in a tabular form in SQL. These commands may be enumerated as follows:<\/span><\/p>\n<h2><strong>For creating databases<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Before creating a database you first need to check what are the databases that are already present. For that, the command is:<\/span><\/p>\n<p><b>mysql&gt; SHOW DATABASES<\/b><span style=\"font-weight: 400;\">;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Fresh databases can be created with the understated command:<\/span><\/p>\n<p><b>mysql&gt; CREATE DATABASE medium;<\/b><\/p>\n<h2><strong>For creating tables<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Tables can be created in databases with the following command. Here is an example of creating a table for students:\u00a0<\/span><\/p>\n<p><b>mysql&gt; CREATE TABLE (Student [table name]) (<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0-&gt; Id int primary key,<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0-&gt; Name varchar(20),<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0-&gt; Subject varchar(20),<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0-&gt; registered char(1)<\/b><\/p>\n<p><b>\u00a0\u00a0\u00a0\u00a0-&gt; );<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The primary key establishes that each row is uniquely identified.<\/span><\/p>\n<h2><strong>Delete a table<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">For deleting a database, you will have to use this command:<\/span><\/p>\n<p><b>mysql&gt; DROP DATABASE medium;<\/b><\/p>\n<h2><strong>Add new columns<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">New columns can be added using the &#8216;alter table&#8217; statement and using the following command:<\/span><\/p>\n<p><b>mysql&gt; ALTER TABLE student ADD gpa DECIMAL(3,2);<\/b><\/p>\n<h2><strong>Delete a column<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">A column can be deleted using the &#8216;alter table&#8217; statement and using the following command:<\/span><\/p>\n<p><b>mysql&gt; ALTER TABLE student DROP gpa;<\/b><\/p>\n<h2><strong>Describe statement<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">if you want to ascertain a specific table\u2019s overview, then the following command will be used:<\/span><\/p>\n<p><b>mysql&gt; DESCRIBE student;<\/b><\/p>\n<h2><strong>Add a new row<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">After the creation of the table, you need to add rows and values to it otherwise it will remain empty. Rows can be added to tables by using the following command:<\/span><\/p>\n<p><b>mysql&gt; INSERT INTO student VALUES(1, &#8220;mary&#8221;, &#8220;accounts&#8221;, &#8220;F&#8221;);<\/b><\/p>\n<p><b>mysql&gt; INSERT INTO student VALUES(2, &#8220;Anderson&#8221;, &#8220;Mathematics&#8221;, &#8220;F&#8221;);<\/b><\/p>\n<p><b>mysql&gt; INSERT INTO student VALUES(3, &#8220;George&#8221;, &#8220;Physics&#8221;, &#8220;S&#8221;);<\/b><\/p>\n<p><b>mysql&gt; INSERT INTO student VALUES(4, &#8220;Natalie&#8221;, &#8220;Biology&#8221;, &#8220;S&#8221;);<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The values have to be in accordance with the predefined data type.<\/span><\/p>\n<h2><strong>Delete a row<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">If you are trying to delete a row then the &#8216;delete from&#8217; command has to be used in the following way:<\/span><\/p>\n<p><b>mysql&gt; DELETE FROM student (table name);<\/b><\/p>\n<p><b>WHERE (condition);<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The condition for deleting the row must be declared after the &#8216;where statement&#8217;.<\/span><\/p>\n<h2><strong>Update a row<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">If any update or addition is required in the rows that already exist, that can also be made in the tables. This command must be used for the same:<\/span><\/p>\n<p><b>mysql&gt; UPDATE student SET subject= &#8220;Accounts&#8221; WHERE Id = 2;<\/b><\/p>\n<p><span style=\"font-weight: 400;\">The update must be specified after the keyword &#8216;set&#8217; and the condition has to be specified after the keyword &#8216;where&#8217;.<\/span><\/p>\n<h2><strong>Select a row or rows<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">Queries are run so that data can be retrieved from databases and the &#8216;select statement&#8217; is used for that purpose. You can specify the row or the column that you need to retrieve data from, using the &#8216;select command&#8217; in the following manner:<\/span><\/p>\n<p><b>mysql&gt; SELECT Name, Subject FROM student (table name);<\/b><\/p>\n<h2><strong>Select based on a condition<\/strong><\/h2>\n<p><span style=\"font-weight: 400;\">To retrieve the data from all the rows while applying some filters and conditions to the rows to make the data analysis more precise, you should use\u00a0 the following command needs to be used:<\/span><\/p>\n<p><b>mysql&gt; SELECT * FROM student WHERE Subject = &#8220;Mathematics&#8221;;<\/b><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Learn data analytics<\/span><span style=\"font-weight: 400;\"> to get a hang of the most important SQL queries to <strong><a href=\"https:\/\/imarticus.org\/postgraduate-program-in-data-science-analytics\/\">become a data scientist<\/a><\/strong>. Enrol in the<\/span> <span style=\"font-weight: 400;\"><strong>Data<\/strong> <strong>Analytics course with placement<\/strong><\/span><strong> by Imarticus<\/strong><span style=\"font-weight: 400;\"> and it will act as a launchpad for your career.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Top 11 SQL queries that a data scientist should know A relational database management system uses SQL for managing data and for storing it in tabular form. SQL stands for Structured Query Language and it is a query language that is extremely useful for data scientists. If you want to learn data analytics and get [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":247109,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_mo_disable_npp":"","_lmt_disableupdate":"no","_lmt_disable":"","footnotes":""},"categories":[23],"tags":[3727],"class_list":["post-248190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","tag-data-scientist-course"],"acf":[],"aioseo_notices":[],"modified_by":"Imarticus Learning","_links":{"self":[{"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/posts\/248190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/comments?post=248190"}],"version-history":[{"count":1,"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/posts\/248190\/revisions"}],"predecessor-version":[{"id":261841,"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/posts\/248190\/revisions\/261841"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/media\/247109"}],"wp:attachment":[{"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/media?parent=248190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/categories?post=248190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imarticus.org\/blog\/wp-json\/wp\/v2\/tags?post=248190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}