{"id":23465,"date":"2023-08-25T02:19:49","date_gmt":"2023-08-25T02:19:49","guid":{"rendered":"https:\/\/machinelearningplus.com\/?p=23465"},"modified":"2023-09-13T17:41:02","modified_gmt":"2023-09-13T17:41:02","slug":"sql-tutorial","status":"publish","type":"post","link":"https:\/\/machinelearningplus.com\/sql\/sql-tutorial\/","title":{"rendered":"SQL Tutorial &#8211; A Simple and Intuitive Guide to the Structured Query Language"},"content":{"rendered":"<p><strong>SQL, short for Structured Query Language is a programming language used to communicate with databases and do various types of Data wrangling operations. This is an essential skillset for any type of Data related jobs. In this tutorial, let&#8217;s get started with the basics of SQL.<\/strong><\/p>\n<h2>1. <strong>Why you should learn SQL<\/strong>?<\/h2>\n<p><strong>First, let&#8217;s understand what is SQL.<\/strong><\/p>\n<p>SQL, pronounced &#8220;see-quel&#8221; or &#8220;S-Q-L&#8221;, is a programming language specifically designed for managing databases.<\/p>\n<p>SQL is used to communicate with databases to retrieve and manipulate data.<\/p>\n<p>Application or websites use databases to store and access data, like user information, transaction data, product details, etc. So, if you have to create such applications, you will need to know at least basic SQL.<\/p>\n<p>It is particularly effective for handling structured data, i.e., data incorporating relations among entities and variables.<\/p>\n<h3>The History of SQL<\/h3>\n<p>SQL was first developed at IBM by <strong>Donald D. Chamberlin and Raymond F. Boyce<\/strong> in the early 1970s.<\/p>\n<p>It was initially called SEQUEL (Structured English Query Language) and was designed to manipulate and retrieve data stored in IBM&#8217;s original quasi-relational database management system, System R, which a group at IBM San Jose Research Laboratory had developed.<\/p>\n<p>Over time, SQL became a standard tool for managing data, and it has been maintained and standardized by the <em>American National Standards Institute (ANSI) and the International Organization for Standardization (ISO)<\/em> since 1986.<\/p>\n<p>It is still effective and in-practice to this day, even modern databases adopting SQL at it&#8217;s core.<\/p>\n<h3>Why Learn SQL?<\/h3>\n<p>It is the most popular, largely accepted way to query data from large databases and do all sorts of data wrangling. It is a basic knowledge requirement expected out of Data professionals.<\/p>\n<blockquote><p>\n  <strong>SQL and relational databases are everywhere!<\/strong><\/p>\n<p>  <strong>Helpful in pursuing a Data Science Career<\/strong><\/p>\n<p>  <strong>Almost every data related technology supports SQL in some form<\/strong><\/p>\n<p>  <strong>Handle large amounts of structured data<\/strong><\/p>\n<p>  <strong>Easy to learn. Get good with practice.<\/strong>\n<\/p><\/blockquote>\n<p>Learning SQL (Structured Query Language) can be advantageous for a number of reasons:<\/p>\n<p>1) <strong>Data Management<\/strong>: SQL is a standard language for managing data held in a relational database management system (RDBMS) or for stream processing in a relational data stream management system (RDSMS).<\/p>\n<p>2) <strong>In Demand Skill<\/strong>: Makes you more marketable for jobs. From data analysts and data scientists to software engineers and database administrators, many jobs require SQL skills.<\/p>\n<p>3) <strong>Data Analysis<\/strong>: SQL is designed not just to manage data, but to retrieve and analyze it. You can use SQL to perform complex queries that help you understand data trends, patterns, and insights.<\/p>\n<p>4) <strong>Interoperability<\/strong>: Almost every RDBMS (like MySQL, Oracle, SQL Server, SQLite, Postgres) uses SQL, even with some differences in dialect. This means that learning SQL gives you skills that you can use across various database systems.<\/p>\n<p>5) <strong>Integrations with Other Languages<\/strong>: SQL integrates with other programming languages such as Python, Java, and R.<\/p>\n<p>6) <strong>Handling Large Databases<\/strong>: SQL can handle databases of all sizes, from a few hundred entries to millions or even billions. This makes it a valuable for companies dealing with big data.<\/p>\n<p>7) <strong>Long-term Relevance<\/strong>: SQL has been around since the 1970s and is still going strong. The importance of SQL in data management ensures its relevance for many years to come.<\/p>\n<p>8) <strong>Ease of Learning<\/strong>: While SQL has depth and complexity. It has a short learning curve but more you practice the better you get at it.<\/p>\n<p>SQL is a powerful and robust tool for extracting relevant and useful data from a large dataset.<\/p>\n<p>While SQL has traditionally been the specialty of highly-trained data analysts and programmers, it&#8217;s finding greater acceptance among non-technical folks.<\/p>\n<h2>2. <strong>Types of SQL servers<\/strong><\/h2>\n<p>SQL servers generally refer to a category of software that provides relational database management system (RDBMS) services, which are often used in conjunction with the SQL (Structured Query Language) programming language.<\/p>\n<p>Here are several types of SQL servers provided by different software vendors:<\/p>\n<ol>\n<li><strong><a href=\"https:\/\/www.microsoft.com\/en-us\/sql-server\/sql-server-downloads\">Microsoft SQL Server<\/a><\/strong>: A widely used commercial SQL server from Microsoft.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/dev.mysql.com\/downloads\/installer\/\">MySQL<\/a><\/strong>: An open-source RDBMS popular for web applications, now owned by Oracle.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/www.postgresql.org\/\">PostgreSQL<\/a><\/strong>: An open-source object-relational database system known for its robustness and complexity.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/www.oracle.com\/in\/database\/technologies\/oracle-database-software-downloads.html\">Oracle Database<\/a><\/strong>: A comprehensive and powerful commercial RDBMS from Oracle Corporation.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/mariadb.org\/download\/\">MariaDB<\/a><\/strong>: An open-source RDBMS, and a community-developed fork of MySQL.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/www.ibm.com\/support\/pages\/downloading-ibm-db2-version-115-linux-unix-and-windows\">IBM DB2<\/a><\/strong>: An enterprise-level, high-performance DBMS from IBM.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/aws.amazon.com\/free\/database\/?tag=buylocal0e8-20\">Amazon RDS<\/a><\/strong>: A scalable and managed RDBMS service from Amazon Web Services.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/cloud.google.com\/sql\/\">Google Cloud SQL<\/a><\/strong>: A fully-managed RDBMS service offered by Google Cloud.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/azure.microsoft.com\/en-in\/products\/azure-sql\">Azure SQL Database<\/a><\/strong>: A fully managed RDBMS service provided by Microsoft&#8217;s Azure Cloud platform.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/www.sqlite.org\/download.html\">SQLite<\/a><\/strong>: A lightweight, disk-based database with an embedded processing model.SQLite is a C library that provides a lightweight disk-based database. It doesn&#8217;t have a separate server process like most other SQL servers.<\/p>\n<\/li>\n<li>\n<p><strong><a href=\"https:\/\/hive.apache.org\/\">Apache HIVE<\/a><\/strong>: Manage petabytes of data residing in distributed storage using SQL.<\/p>\n<\/li>\n<\/ol>\n<p>The <strong>sqlite3 module in Python<\/strong> provides an SQL interface for interacting with <strong>SQLite databases<\/strong>. This module is an embedded SQL database engine and does not have a separate server process.<\/p>\n<h2>4. <strong>What is a Database and Table?<\/strong><\/h2>\n<p>Before you start learning SQL, it is very important to understand what is Database and Table?<\/p>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/library.png\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/library.png\" alt=\"\" width=\"997\" height=\"489\" class=\"aligncenter size-full wp-image-23475\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/library.png 997w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/library-300x147.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/library-768x377.png 768w\" sizes=\"(max-width: 997px) 100vw, 997px\" \/><\/a><\/p>\n<p>1) <strong>Database<\/strong>: Imagine a library. It&#8217;s a place where lots of information is stored. This information is organized in a way that you can find and access what you&#8217;re looking for.<\/p>\n<p>A database is the equivalent of this library in the digital world. It&#8217;s a structured set of data. So, a database might be used to store information for a website, a business, a game, and so on. It helps us store, manage, and retrieve that information efficiently.<\/p>\n<p>2) <strong>Tables<\/strong>: Now within this library, books are organized into different sections or shelves based on categories like &#8216;Science Fiction&#8217;, &#8216;History&#8217;, &#8216;Biography&#8217; and so forth. Tables are just like these sections in our library analogy.<\/p>\n<p>In a database, a table is a set of data elements (values) that is organized using a model of vertical columns (which are identified by their name) and horizontal rows, the cell being the unit where a <strong>row and column<\/strong> intersect.<\/p>\n<p>A table has a specified number of columns, but can have any number of rows.<\/p>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/RelationalDB.png\"><img decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/RelationalDB.png\" alt=\"\" width=\"974\" height=\"457\" class=\"aligncenter size-full wp-image-23467\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/RelationalDB.png 974w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/RelationalDB-300x141.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/RelationalDB-768x360.png 768w\" sizes=\"(max-width: 974px) 100vw, 974px\" \/><\/a><\/p>\n<h2>SQL Syntax example<\/h2>\n<p>Typically we write SQL Commands in CAPS. However, SQL is NOT case sensitive.  So, <code>SELECT<\/code> is same as <code>select<\/code> in SQL.<\/p>\n<pre><code class=\"language-sql\">SELECT ProductID, CustomerID, COUNT(*)\nFROM Orders\nWHERE Quantity &gt; 0\nGROUP BY ProductID, CustomerID\nHAVING COUNT(*) &gt; 5\nORDER BY ProductID ASC, CustomerID DESC;\n<\/code><\/pre>\n<p>Explanation:<\/p>\n<ul>\n<li><strong>SELECT<\/strong>: Retrieve specific columns or expressions from the table.<\/li>\n<li><strong>FROM<\/strong>: Specify the table from which to retrieve data.<\/li>\n<li><strong>WHERE<\/strong>: Filter the data based on specific conditions.<\/li>\n<li><strong>GROUP BY<\/strong>: Group the result set based on one or more columns.<\/li>\n<li><strong>HAVING<\/strong>: Filter the grouped data based on conditions.<\/li>\n<li><strong>ORDER BY<\/strong>: Sort the result set based on one or more columns.<\/li>\n<\/ul>\n<h2>5. <strong>Setup Python Environment for SQL<\/strong><\/h2>\n<ol>\n<li>Install Anaconda <\/li>\n<li>Or Use Google Colab<\/li>\n<\/ol>\n<p>Check instuctions in respective video lessons in <a href=\"https:\/\/edu.machinelearningplus.com\/courses\/Python-Programming-628f8abb0cf22aee960e8234\">Python Course<\/a><\/p>\n<h2>6. <strong>Import necessary libraries and create sample data<\/strong><\/h2>\n<p>Here is the plan:<\/p>\n<p>We are going to use pandas to load a CSV file as a Pandas Dataframe. Then we will load this dataframe to SQL Database. From then on, we will do all the work \/ data processing in SQL.<\/p>\n<p><strong>Note:<\/strong><\/p>\n<p>Typically, in workplace scenarios, this step is done for you and not required. Your org will typically already have the databases with tables. Nevertheless, let&#8217;s see how to create one if not already given so you get the full picture.<\/p>\n<pre><code class=\"language-python\">#!pip install pandas\nimport pandas as pd\nsample_df = pd.read_csv('DataSQL.csv')\nsample_df.head()\n<\/code><\/pre>\n<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }<\/p>\n<p>    .dataframe tbody tr th {\n        vertical-align: top;\n    }<\/p>\n<p>    .dataframe thead th {\n        text-align: right;\n    }\n<\/style>\n<table border=\"1\" class=\"dataframe\">\n<thead>\n<tr style=\"text-align: right;\">\n<th><\/th>\n<th>Current_id<\/th>\n<th>Dep_Var<\/th>\n<th>Logit_Var<\/th>\n<th>Var_1<\/th>\n<th>Var_2<\/th>\n<th>Var_3<\/th>\n<th>Var_4<\/th>\n<th>Var_5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>0<\/th>\n<td>301897853<\/td>\n<td>16428<\/td>\n<td>0<\/td>\n<td>-113<\/td>\n<td>40000<\/td>\n<td>436<\/td>\n<td>105<\/td>\n<td>13<\/td>\n<\/tr>\n<tr>\n<th>1<\/th>\n<td>301934672<\/td>\n<td>8678<\/td>\n<td>1<\/td>\n<td>-120<\/td>\n<td>35000<\/td>\n<td>446<\/td>\n<td>113<\/td>\n<td>15<\/td>\n<\/tr>\n<tr>\n<th>2<\/th>\n<td>301902540<\/td>\n<td>25561<\/td>\n<td>1<\/td>\n<td>-99<\/td>\n<td>36000<\/td>\n<td>456<\/td>\n<td>132<\/td>\n<td>14<\/td>\n<\/tr>\n<tr>\n<th>3<\/th>\n<td>301864713<\/td>\n<td>8528<\/td>\n<td>0<\/td>\n<td>-85<\/td>\n<td>21600<\/td>\n<td>408<\/td>\n<td>142<\/td>\n<td>14<\/td>\n<\/tr>\n<tr>\n<th>4<\/th>\n<td>301937240<\/td>\n<td>10128<\/td>\n<td>0<\/td>\n<td>-118<\/td>\n<td>38000<\/td>\n<td>396<\/td>\n<td>139<\/td>\n<td>13<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2>Basic outline to follow while learning SQL in a structured manner<\/h2>\n<ol>\n<li>Create a Database<\/li>\n<li>Create and Load Table in Database<\/li>\n<li>Create New Table from existing table<\/li>\n<li>Copy data from one table and insert it into already exisitng table<\/li>\n<li>Get list of tables in SQL DB<\/li>\n<li>Drop Tables in DB<\/li>\n<li>Delete rows in a existing Dataset using where condition<\/li>\n<li>Update rows\/columns in a existing Dataset<\/li>\n<li>Select data \/ required vaiables from a dataset<\/li>\n<li>SQL Comments<\/li>\n<li>Limit the number of rows returned from a query<\/li>\n<li>Identify and Delete duplicates in a dataset<\/li>\n<li>Filter rows in SQL dataset<\/li>\n<li>Sort the data in ascending or descending order<\/li>\n<li>Aggregate identical data into groups<\/li>\n<li>Filter rows after the aggregated<\/li>\n<li>SQL Joins\n<ul>\n<li>17(a) &#8211; Inner Join<\/li>\n<li>17(b) &#8211; Full Join<\/li>\n<li>17(c) &#8211; Left Join<\/li>\n<li>17(d) &#8211; RIght Join<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2>1. <strong>Create DB and Run SQL in Jupyter Environment<\/strong><\/h2>\n<p>Database in SQL is used to <strong>manage and manipulate<\/strong> the data.<\/p>\n<p>In this Database, data is organized into tables which are related to each other based on common keys or concepts; hence the term &#8220;relational database&#8221;.<\/p>\n<p>Each table consists of columns (fields) and rows (records). A unique key identifies each record in a table, and relationships between tables are created through these keys.<\/p>\n<p>Python ships with a default SQL database called &#8216;sqlite&#8217;. Let&#8217;s connect to the db that comes with this course called <code>jupyter_sql_tutorial.db<\/code>.<\/p>\n<p><strong>STEP 1: CONNECT or CREATE<\/strong><\/p>\n<pre><code class=\"language-python\"># !pip install db-sqlite3\nimport sqlite3\n\n# Use sqlite3 library to create a database connection\nTest_db = sqlite3.connect('jupyter_sql_tutorial.db')\n<\/code><\/pre>\n<p><strong>If the database does not exist, it will create a new one.<\/strong><\/p>\n<pre><code class=\"language-python\"># Create new database if not exist\nTest_db2 = sqlite3.connect('new_database.db')\n<\/code><\/pre>\n<p>If you check the work directory, it should contain a new file named <code>new_database.db<\/code>.<\/p>\n<p><em>Important: Install ipython-sql for the <code>%sql<\/code> function to work<\/em><\/p>\n<pre><code class=\"language-python\"># Common error: https:\/\/stackoverflow.com\/questions\/37149748\/ipython-notebook-and-sql-importerror-no-module-named-sql-when-running-load\n# !pip install ipython-sql\n<\/code><\/pre>\n<p><strong>STEP 2: LOAD DATABASE and ATTACH<\/strong><\/p>\n<p>In database management systems, the <strong>&#8220;ATTACH DATABASE&#8221;<\/strong> statement is used to connect or link an external database to the current database session.<\/p>\n<pre><code class=\"language-python\">%load_ext sql\n%sql sqlite:\/\/\/jupyter_sql_tutorial.db\n<\/code><\/pre>\n<p>Important note, if you want to run this code in Jupyter notebook:<\/p>\n<ul>\n<li>Add &#8216;%%sql&#8217; in the beginning of each cell so Jupyter knows the cell contains SQL code.<\/li>\n<li>Do &#8216;Attach Database&#8217; so we can refer &#8216;jupyter_sql_tutorial.db&#8217; as &#8216;test_db&#8217;.<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">ATTACH DATABASE 'jupyter_sql_tutorial.db' AS Test_db;\n<\/code><\/pre>\n<p><strong>STEP 3: Save Pandas DataFrame to SQL Database (Test_db)<\/strong><\/p>\n<pre><code class=\"language-python\"># Load the dataset if not already loaded.\ntry:\n    sample_df.to_sql('sample_df', Test_db)\nexcept:\n    pass\n<\/code><\/pre>\n<p><em>Note: If above statement gives error that the table <code>sample_df<\/code> already exists, then it means the table has already been loaded, so no need to re-run.<\/em><\/p>\n<p>View \/ Print <code>sample_df<\/code> Loaded into <code>Test_db<\/code><\/p>\n<p>Now, let&#8217;s read the data from the <code>Sample_df<\/code> table stored in <code>Test_db<\/code><\/p>\n<p>Notice the syntax.<\/p>\n<pre><code class=\"language-sql\">SELECT *\nFROM Test_db.Sample_df\n<\/code><\/pre>\n<p>This prints the entire table. Not showing here because of long output.<\/p>\n<p>The above output was too long, and can easily run out of memory for large tables.<\/p>\n<p>So, let&#8217;s get only 5 rows.<\/p>\n<pre><code class=\"language-sql\">SELECT *\nFROM Test_db.Sample_df\nLIMIT 5;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>index<\/th>\n<th>Current_id<\/th>\n<th>Dep_Var<\/th>\n<th>Logit_Var<\/th>\n<th>Var_1<\/th>\n<th>Var_2<\/th>\n<th>Var_3<\/th>\n<th>Var_4<\/th>\n<th>Var_5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>0<\/td>\n<td>301897853<\/td>\n<td>16428<\/td>\n<td>0<\/td>\n<td>-113<\/td>\n<td>40000<\/td>\n<td>436<\/td>\n<td>105<\/td>\n<td>13<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>301934672<\/td>\n<td>8678<\/td>\n<td>1<\/td>\n<td>-120<\/td>\n<td>35000<\/td>\n<td>446<\/td>\n<td>113<\/td>\n<td>15<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>301902540<\/td>\n<td>25561<\/td>\n<td>1<\/td>\n<td>-99<\/td>\n<td>36000<\/td>\n<td>456<\/td>\n<td>132<\/td>\n<td>14<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>301864713<\/td>\n<td>8528<\/td>\n<td>0<\/td>\n<td>-85<\/td>\n<td>21600<\/td>\n<td>408<\/td>\n<td>142<\/td>\n<td>14<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>301937240<\/td>\n<td>10128<\/td>\n<td>0<\/td>\n<td>-118<\/td>\n<td>38000<\/td>\n<td>396<\/td>\n<td>139<\/td>\n<td>13<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>How to count the number of records in the table<\/strong>?<\/p>\n<pre><code class=\"language-sql\">SELECT count(*)\nFROM Test_db.Sample_df;\n<\/code><\/pre>\n<p>14989<\/p>\n<p><strong>How to count the columns?<\/strong><\/p>\n<p>That is not the right way to think about it. Let me explain.<\/p>\n<p>In Python, you normally get the count of columns to reference the column by column index or do some iterations.<\/p>\n<p>Whereas in SQL, we reference the columns by the respective column names. All the operations we do is vectorised (applied on the entire data).<\/p>\n<p>Nevertheless, SQL does not prevent you from finding the count of columns, but how you compute it depends on what RDBMS you work on.<\/p>\n<p>Here are couple of ways to do it: <a href=\"https:\/\/stackoverflow.com\/questions\/658395\/find-the-number-of-columns-in-a-table\">MySQL<\/a>,  <a href=\"https:\/\/www.sqlite.org\/pragma.html#pragma_table_info\">SQLite<\/a><\/p>\n<pre><code class=\"language-sql\">SELECT COUNT(*)\nFROM pragma_table_info('Sample_df');\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>COUNT(*)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>2. <strong>Data wrangling in SQL vs Python<\/strong><\/h2>\n<p>A key difference in Data Wrangling between SQL and Python is: In Python, you can create your own functions, iterate in a customized way by writing For Loops. But in SQL, we accomplish all tasks by the limited set of predefined SQL commands.<\/p>\n<h2>3. <strong>Setup MySQL Workbench<\/strong><\/h2>\n<p>Helpful Article:<br \/>\n1. <a href=\"https:\/\/www.dataquest.io\/blog\/install-mysql-windows\/\">How to install MySQL on Windows<\/a><br \/>\n2. <a href=\"https:\/\/www.devart.com\/dbforge\/mysql\/how-to-install-mysql-on-macos\/\">How to install MySQL on MacOS<\/a><br \/>\n3. Official Guide: <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/windows-installation.html\">Windows<\/a>, <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/macos-installation-pkg.html\">MacOS<\/a><\/p>\n<p>With time, these article links may change. To get the latest just google search &#8220;Install MySQL in Windows&#8221; (or Mac) and look into the latest article.<\/p>\n<p><strong>Steps<\/strong><\/p>\n<ol>\n<li>Download MYSQL installer: https:\/\/dev.mysql.com\/downloads\/installer\/<\/li>\n<li>Once installation completes select the &#8216;Full&#8217; setup option.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_1.png.jpg\"><img decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_1.png.jpg\" alt=\"\" width=\"870\" height=\"653\" class=\"aligncenter size-full wp-image-23468\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_1.png.jpg 870w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_1.png-300x225.jpg 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_1.png-768x576.jpg 768w\" sizes=\"(max-width: 870px) 100vw, 870px\" \/><\/a><\/p>\n<ol>\n<li>In &#8216;Type and Networking&#8217; screen, keep it as &#8216;Development Computer&#8217; if you are using a personal PC.<br \/>\nKeep the default port or you can give your own.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_2.png\" alt=\"\" width=\"874\" height=\"660\" class=\"aligncenter size-full wp-image-23469\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_2.png 874w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_2-300x227.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_2-768x580.png 768w\" sizes=\"(max-width: 874px) 100vw, 874px\" \/><\/a><\/p>\n<ol>\n<li>Continue default method until it asks you to give root account password.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_3.png\" alt=\"\" width=\"870\" height=\"658\" class=\"aligncenter size-full wp-image-23470\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_3.png 870w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_3-300x227.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_3-768x581.png 768w\" sizes=\"(max-width: 870px) 100vw, 870px\" \/><\/a><\/p>\n<ol>\n<li>Apply configuration and Finish.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_4.png\" alt=\"\" width=\"874\" height=\"659\" class=\"aligncenter size-full wp-image-23471\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_4.png 874w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_4-300x226.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_4-768x579.png 768w\" sizes=\"(max-width: 874px) 100vw, 874px\" \/><\/a><\/p>\n<p>Done! The next step is to connect to the server. Type the root account&#8217;s password and click Check<\/p>\n<ol>\n<li>In MySQL Router configuration, uncheck this box and click next.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_5.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_5.png\" alt=\"\" width=\"872\" height=\"655\" class=\"aligncenter size-full wp-image-23472\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_5.png 872w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_5-300x225.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_5-768x577.png 768w\" sizes=\"(max-width: 872px) 100vw, 872px\" \/><\/a><\/p>\n<ol>\n<li>Once everything is set, you will be greeted with the workbench screen. Choose the connection to the server you had created and log into it.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_6.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_6.png\" alt=\"\" width=\"873\" height=\"509\" class=\"aligncenter size-full wp-image-23473\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_6.png 873w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_6-300x175.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_6-768x448.png 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><\/a><\/p>\n<ol>\n<li>You can now start writing your queries.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_7.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_7.png\" alt=\"\" width=\"873\" height=\"650\" class=\"aligncenter size-full wp-image-23474\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_7.png 873w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_7-300x223.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_7-768x572.png 768w\" sizes=\"(max-width: 873px) 100vw, 873px\" \/><\/a><\/p>\n<h3><strong>Information on Sakila Database we use for Exercises<\/strong><\/h3>\n<p>The sakila database is very popular, basic set of tables that comes preinstalled by default when you install MySQL server in the workbench. If it&#8217;s not present in anycase, you can find out more about the database and set it up using the following links:<\/p>\n<ol>\n<li>Structure of DB: https:\/\/dev.mysql.com\/doc\/sakila\/en\/sakila-structure.html<\/li>\n<li>Installation: https:\/\/dev.mysql.com\/doc\/sakila\/en\/sakila-installation.html<\/li>\n<li>Download link: https:\/\/dev.mysql.com\/doc\/index-other.html<\/li>\n<li>Alternate Download Link: https:\/\/www.sqliz.com\/sakila\/installation\/<\/li>\n<\/ol>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_8.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_8.png\" alt=\"\" width=\"870\" height=\"752\" class=\"aligncenter size-full wp-image-23476\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_8.png 870w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_8-300x259.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/mysql_8-768x664.png 768w\" sizes=\"(max-width: 870px) 100vw, 870px\" \/><\/a><\/p>\n<h2>2. <strong>Create Table manually in DB<\/strong><\/h2>\n<p>Tables are an essential component of databases as they hold all the data. When a table is created, the name of the table, names of columns, and the type of data that can be stored in the columns are defined.<\/p>\n<p>The <code>CREATE TABLE<\/code> statement in SQL is used to create a new table in a database with <strong>&#8220;0 Rows&#8221;<\/strong>.<\/p>\n<pre><code class=\"language-sql\">CREATE TABLE Students (\n  StudentID int PRIMARY KEY,\n  FirstName varchar(255),\n  LastName varchar(255),\n  Age int,\n  Grade int\n);\n\nSELECT * FROM Students\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n    <\/tbody>\n<\/table>\n<p>Add rows manually to <strong>Students<\/strong> table<\/p>\n<pre><code class=\"language-sql\">INSERT INTO Students (StudentID, FirstName, LastName, Age, Grade)\nVALUES (1, 'John', 'Doe', 15, 10),\n       (2, 'Jane', 'Doe', 14, 9),\n       (3, 'Jim', 'Beam', 16, 10),\n       (4, 'Jack', 'Daniels', 15, 9);\n\nSELECT * FROM Students\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Get Table Variables types<\/p>\n<pre><code class=\"language-sql\">PRAGMA table_info(Students);\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>cid<\/th>\n<th>name<\/th>\n<th>type<\/th>\n<th>notnull<\/th>\n<th>dflt_value<\/th>\n<th>pk<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>0<\/td>\n<td>StudentID<\/td>\n<td>INT<\/td>\n<td>0<\/td>\n<td>None<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>FirstName<\/td>\n<td>varchar(255)<\/td>\n<td>0<\/td>\n<td>None<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>LastName<\/td>\n<td>varchar(255)<\/td>\n<td>0<\/td>\n<td>None<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Age<\/td>\n<td>INT<\/td>\n<td>0<\/td>\n<td>None<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Grade<\/td>\n<td>INT<\/td>\n<td>0<\/td>\n<td>None<\/td>\n<td>0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>PRAGMA<\/code> is a sqlite specific command. If you are working on other databases, say MySQL, use <code>DESCRIBE<\/code> command.<\/p>\n<pre><code class=\"language-python\">DESCRIBE Students\n<\/code><\/pre>\n<h3>SQL Variables Types:<\/h3>\n<p>Creating a table in SQL requires defining not only the column names but also the data types for each column. The most common types of data used in SQL are:<\/p>\n<p>A) <code>INT<\/code>: For integer numbers<\/p>\n<p>B) <code>FLOAT<\/code> or <code>DOUBLE<\/code>: For floating point numbers<\/p>\n<p>C) <code>DATE<\/code>: For date values<\/p>\n<p>D) <code>TIMESTAMP<\/code>: For date and time values<\/p>\n<p>E) <code>CHAR(size)<\/code>: For fixed length strings (size = number of characters)<\/p>\n<p>F) <code>VARCHAR(size)<\/code>: For variable length strings (size = maximum number of characters)<\/p>\n<p>G) <code>TEXT<\/code>: For storing large amount of text<\/p>\n<p>I) <code>BIT<\/code>: For storing either true or false logical values.<\/p>\n<p>J) <code>BLOB<\/code><\/p>\n<p>Here is a sample SQL command to create a table with various types of variables:<\/p>\n<pre><code class=\"language-sql\">CREATE TABLE Employee (\n    EmployeeID INT PRIMARY KEY,\n    FirstName VARCHAR(50),\n    LastName VARCHAR(50),\n    BirthDate DATE,\n    HireDate TIMESTAMP,\n    Salary DOUBLE,\n    Bio TEXT,\n    Photo BLOB,\n    IsActive BIT\n);\n<\/code><\/pre>\n<h2>2b. Exercise: Create Orders table from raw data.<\/h2>\n<p>Try the following in Jupyter or MySQL Workbench.<\/p>\n<ol>\n<li>Create a database &#8216;homework&#8217;.<\/p>\n<\/li>\n<li>\n<p>Create an orders table in &#8216;homework&#8217; containing the following fields:<\/p>\n<ul>\n<li>OrderID<\/li>\n<li>OrderDate<\/li>\n<li>Qty<\/li>\n<li>Customer ID<\/li>\n<li>Product category<\/li>\n<li>Price<\/li>\n<\/ul>\n<\/li>\n<li>Then insert the following entries.\n<ul>\n<li>1, 2023-01-01, 2, 10, &#8220;Electronics&#8221;, 110<\/li>\n<li>2, 2023-01-01, 2, 11, &#8220;Home&#8221;, 10<\/li>\n<li>3, 2023-01-01, 2, 11, &#8220;Kitchen&#8221;, 80<\/li>\n<li>4, 2023-01-01, 2, 12, &#8220;Electronics&#8221;, 11<\/li>\n<li>5, 2023-01-01, 2, 12, &#8220;Outdoor&#8221;, 19<\/li>\n<li>6, 2023-01-01, 2, 13, &#8220;Outdoor&#8221;, 217<\/li>\n<li>7, 2023-01-01, 2, 13, &#8220;Home&#8221;, 8<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2>3. <strong>Create New Table from existing table<\/strong><\/h2>\n<p>The &#8220;CREATE TABLE&#8221; statement copies data from one table and <strong>inserts it into a new table<\/strong>.<\/p>\n<pre><code class=\"language-sql\">CREATE TABLE Students_test AS \nSELECT * FROM Students\nWHERE Grade &lt; 10;\n\nSELECT * FROM Students_test\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2>4. <strong>Show Tables from existing Database<\/strong><\/h2>\n<p>Different RDBMS (like SQLite, MySQL.. ) have different ways of doing this. The two most common methods are shown below.<\/p>\n<p>For SQLite, this info is stored in an in-built database called <code>sqlite_master<\/code>. You can query that table using the following command.<\/p>\n<pre><code class=\"language-sql\">SELECT name FROM sqlite_master WHERE type='table';\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>sample_df<\/td>\n<\/tr>\n<tr>\n<td>Students<\/td>\n<\/tr>\n<tr>\n<td>Employee<\/td>\n<\/tr>\n<tr>\n<td>Students_test<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In MYSQL databases, you can use the <code>SHOW TABLES<\/code> command. This is very common in most RDBMS.<\/p>\n<pre><code class=\"language-sql\">SHOW TABLES FROM {DB_NAME};\n<\/code><\/pre>\n<p>Ref: https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/show-tables.html<\/p>\n<h2>5. <strong>Insert Into Select: copy data from one table to another table<\/strong><\/h2>\n<p><code>Insert Into Select<\/code> is a versatile feature that can be utilized to <strong>copy data from one table and insert it into already exisitng table.<\/strong><\/p>\n<p>It will not copy to a new table.<\/p>\n<pre><code class=\"language-sql\">INSERT INTO Students_test\nSELECT *\nFROM Students;\n\nSELECT * FROM Students_test\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Create one more<\/strong><\/p>\n<pre><code class=\"language-sql\">INSERT INTO Students_test2\nSELECT *\nFROM Students;\n\nSELECT * FROM Students_test2\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This did not work.<\/p>\n<p>Why?<\/p>\n<p>Because <code>Student_test2<\/code> table did not exist. So, you need to first create it.<\/p>\n<pre><code class=\"language-sql\">CREATE TABLE Students_test2 AS \nSELECT * FROM Students\nWHERE Grade &lt; 10;\n\nSELECT * FROM Students_test2\n<\/code><\/pre>\n<pre><code> * sqlite:\/\/\/jupyter_sql_tutorial.db\n(sqlite3.OperationalError) table Students_test2 already exists\n[SQL: CREATE TABLE Students_test2 AS \nSELECT * FROM Students\nWHERE Grade &lt; 10;]\n(Background on this error at: https:\/\/sqlalche.me\/e\/20\/e3q8)\n<\/code><\/pre>\n<p><strong>Check if new table was created<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT name \nFROM sqlite_master \nWHERE type='table';\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>sample_df<\/td>\n<\/tr>\n<tr>\n<td>Students<\/td>\n<\/tr>\n<tr>\n<td>Employee<\/td>\n<\/tr>\n<tr>\n<td>Students_test<\/td>\n<\/tr>\n<tr>\n<td>Students_test2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>6. <strong>SQL DELETE: Delete rows in a existing Dataset using where condition<\/strong><\/h2>\n<p><code>DELETE<\/code> command can be used to delete a single record, multiple records, or all records from a table.<\/p>\n<pre><code class=\"language-sql\">DELETE FROM Students_test2\nWHERE Grade = 9;\n\nSELECT * FROM Students_test2\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can give more complex conditions as well.<\/p>\n<pre><code class=\"language-sql\">DELETE FROM Students_test2\nWHERE Grade = 9 AND AGE = 15;\n\nSELECT * FROM Students_test2\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>7. <strong>Delete a Table<\/strong><\/h2>\n<p>You can delete \/ drop an entire table in a single <code>DROP TABLE<\/code> command. So, be absolutely sure before running this.<\/p>\n<p>The <code>DROP TABLE<\/code> command in SQL is a Data Definition Language (DDL) statement used to remove a table definition along with all the data, indexes, triggers, constraints, and permission specifications for that table. Essentially, the command completely eliminates the table from the database.<\/p>\n<p>It is important to exercise caution when using this command because once a table is dropped, all the information in the table is lost and cannot be recovered (unless you have a backup).<\/p>\n<pre><code class=\"language-sql\">DROP TABLE Students_test2;\n<\/code><\/pre>\n<h3>Check the DROP TABLE Command after dropping table (Students_test2) in Database<\/h3>\n<p>It will give an error, because, it does not exist anymore.<\/p>\n<pre><code class=\"language-sql\">DROP TABLE Students_test2;\n<\/code><\/pre>\n<pre><code> * sqlite:\/\/\/jupyter_sql_tutorial.db\n(sqlite3.OperationalError) no such table: Students_test2\n[SQL: DROP TABLE Students_test2;]\n(Background on this error at: https:\/\/sqlalche.me\/e\/20\/e3q8)\n<\/code><\/pre>\n<p><strong>Check tables in the Database<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT name \nFROM sqlite_master \nWHERE type='table';\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>sample_df<\/td>\n<\/tr>\n<tr>\n<td>Students<\/td>\n<\/tr>\n<tr>\n<td>Employee<\/td>\n<\/tr>\n<tr>\n<td>Students_test<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>8. <strong>SQL Update : Update rows\/columns in a existing Dataset<\/strong><\/h2>\n<p>The <code>UPDATE<\/code> statement is used to modify existing records in a table<\/p>\n<pre><code class=\"language-sql\">UPDATE Students\nSET Grade = Grade * 10, \n    Age = Age + 2\nWHERE FirstName = 'Jane';\n\nSELECT * FROM Students\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>16<\/td>\n<td>90<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>8b. Exercise 2: Updating Table<\/h2>\n<p>Try the following in MySQL Workbench on the Sakila Database<\/p>\n<ol>\n<li>Set to use the database as Sakila.<\/li>\n<li>Update Sakila.FILM to increase all values &#8216;Rental_Duration&#8217; by 5<\/li>\n<\/ol>\n<p>Note:<\/p>\n<ul>\n<li>The Sakila db is present as a default database in MySQL workbench.<br \/>\nIf not present, follow the instructions in the &#8216;Setup MySQL WorkBench&#8217; lesson above to set it up.<\/p>\n<\/li>\n<li>\n<p>Basically, you need to run the 2 SQL scripts inside &#8216;Sakila-db&#8217; directory: sakila-schema.sql, then, sakila-data.sql.<\/p>\n<\/li>\n<\/ul>\n<h2>9. <strong>SQL Select : Select data \/ required vaiables from a dataset<\/strong><\/h2>\n<p>The SELECT statement is used to select data from a database.<\/p>\n<p><code>Select *<\/code> is used to select <strong>all colums<\/strong> in the table<\/p>\n<pre><code class=\"language-sql\">SELECT *\nFROM Students;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>16<\/td>\n<td>90<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Select only defined columns <code>SELECT FirstName, LastName<\/code><\/p>\n<pre><code class=\"language-sql\">SELECT FirstName, LastName\nFROM Students;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>John<\/td>\n<td>Doe<\/td>\n<\/tr>\n<tr>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<\/tr>\n<tr>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<\/tr>\n<tr>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Select Only &#8216;Jane&#8217; and &#8216;Jack&#8217;<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT FirstName, LastName\nFROM Students\nWHERE FirstName in (\"Jane\", \"Jack\");\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<\/tr>\n<tr>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Select all except &#8216;Jane&#8217; and &#8216;Jack&#8217;<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT FirstName, LastName\nFROM Students\nWHERE FirstName not in (\"Jane\", \"Jack\");\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>John<\/td>\n<td>Doe<\/td>\n<\/tr>\n<tr>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Select all where LastName startd with &#8220;D&#8221;<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT FirstName, LastName\nFROM Students\nWHERE LastName LIKE (\"D%\");\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>John<\/td>\n<td>Doe<\/td>\n<\/tr>\n<tr>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<\/tr>\n<tr>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>More on such patterns in an upcoming section.<\/p>\n<h2>10. <strong>SQL Comments<\/strong><\/h2>\n<p>Comments are lines of text in your SQL code that the SQL interpreter or compiler ignores<\/p>\n<p>SQL offers two types of comment syntax:<\/p>\n<ol>\n<li>Single-Line Comments<\/p>\n<\/li>\n<li>\n<p>Multi-Line Comments<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"language-sql\">-- This is a single-line comment\n\n\/*\n  This is a multi-line comment.\n  The SELECT statement below retrieves all records from the Customers table.\n*\/\n\nSELECT * FROM Students;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>16<\/td>\n<td>90<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>11. <strong>Limit the number of rows returned from a query<\/strong><\/h2>\n<p>The <code>SELECT TOP<\/code> clause is a SQL command used to limit the number of rows returned from a query. This is particularly useful when you&#8217;re dealing with large databases, and you want a subset of records.<\/p>\n<h3>Fetching Top N Records<\/h3>\n<p>If you want to select the top 3 orders<\/p>\n<p>The <code>LIMIT<\/code> clause is used to limit the number of records returned by the query. For example, if you set <code>LIMIT 3<\/code>, it will return only the first 3 records from the result set.<\/p>\n<p><strong>First, let&#8217;s print all rows<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT * \nFROM Students_test;\n<\/code><\/pre>\n<p><strong>Only 3 rows<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT * \nFROM Students_test LIMIT 3;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The <code>OFFSET<\/code> clause is used to specify the starting point for the rows to be returned. If you set <code>OFFSET 2<\/code>, it means that the first 2 rows will be skipped and the query will start returning records from the 3rd row.<\/p>\n<p>So, when you combine <code>LIMIT 3 OFFSET 2<\/code> in a SQL query, it means that the SQL statement will skip the first 2 records and then return the next 3 records.<\/p>\n<pre><code class=\"language-sql\">SELECT * \nFROM Students_test \nLIMIT 3 OFFSET 2;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>12. <strong>SELECT DISTINCT : Identify and Delete duplicates in a dataset<\/strong><\/h2>\n<p>The primary function of the <code>SELECT DISTINCT<\/code> statement is to eliminate all duplicate rows and present a table of unique rows.<\/p>\n<p>Sample data for understanding SELECT DISTINCT<\/p>\n<pre><code class=\"language-sql\">SELECT * \nFROM Students_test \n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>SELECT DISTINCT *<\/code> Get distinct of entire row<\/p>\n<pre><code class=\"language-sql\">SELECT DISTINCT *\nFROM Students_test;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>SELECT DISTINCT StudentID<\/code> Get distinct of Selected column(s)<\/p>\n<pre><code class=\"language-sql\">SELECT DISTINCT StudentID\nFROM Students_test;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>13. <strong>SQL Where: Filtering rows<\/strong><\/h2>\n<p>The SQL WHERE clause is the filtering mechanism in SQL. It specifies a condition while fetching data from a single table or by joining with multiple tables. If the given condition is satisfied, only then it returns a specific value from the table.<\/p>\n<p>You could say the WHERE clause is the gatekeeper of data &#8211; only letting through the data you specifically request.<\/p>\n<pre><code class=\"language-sql\">Select *\nFROM Students_test\nWHERE Grade &lt; 10;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Multiple conditions<\/strong><\/p>\n<pre><code class=\"language-sql\">Select *\nFROM Students_test\nWHERE Age &gt; 14 AND Grade &lt; 10;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Select specific STUDENTIDs<\/strong><\/p>\n<pre><code class=\"language-sql\">Select *\nFROM Students_test\nWHERE StudentID in (2,3,4);\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>13b. Exercise 3: Filtering Data<\/h2>\n<p>Try the following in MySQL Workbench on the Sakila Database<\/p>\n<ol>\n<li>From SAKILA.FILM, select only the film titles and description with rental rate more than 2.00 and Rating is &#8216;PG&#8217;.<\/p>\n<\/li>\n<li>\n<p>From SAKILA.PAYMENTS, count how many payments were make more than $5.<\/p>\n<\/li>\n<\/ol>\n<p>Note:<\/p>\n<ul>\n<li>The Sakila db is present as a default database in MySQL workbench.<br \/>\nIf not present, follow the instructions in the &#8216;Setup MySQL WorkBench&#8217; lesson above to set it up.<\/p>\n<\/li>\n<li>\n<p>Basically, you need to run the 2 SQL scripts inside &#8216;Sakila-db&#8217; directory: sakila-schema.sql, then, sakila-data.sql.<\/p>\n<\/li>\n<\/ul>\n<h2>14. <strong>SQL Order By: Sort the data in ascending or descending order<\/strong><\/h2>\n<p>The SQL <code>ORDER BY<\/code> keyword is used to sort the result-set in <strong>ascending or descending<\/strong> order. The <code>ORDER BY<\/code> keyword sorts the records in ascending order by default. If you want to sort the records in descending order, you can use the DESC keyword.<\/p>\n<pre><code class=\"language-sql\">SELECT * \nFROM Students_test \nORDER BY Grade ASC;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><code>ORDER BY Grade ASC, Age DESC;<\/code> Sort \/ Order using multiple variables and diffrent order types <strong>(ASC, DESC)<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT * \nFROM Students_test \nORDER BY Grade ASC, Age DESC;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>LastName<\/th>\n<th>Age<\/th>\n<th>Grade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>Daniels<\/td>\n<td>15<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>Doe<\/td>\n<td>14<\/td>\n<td>9<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>Beam<\/td>\n<td>16<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>Doe<\/td>\n<td>15<\/td>\n<td>10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>15. <strong>SQL Group By : Aggregate identical data into groups<\/strong><\/h2>\n<p>&#8216;GROUP BY&#8217; is an SQL command that arranges identical data into groups.<\/p>\n<p>&#8216;GROUP BY&#8217; goes hand in hand with aggregate functions like COUNT, AVG, SUM, MAX, or MIN to provide meaningful insights from the data. It enables you to perform calculations on each group of rows rather than individual rows.<\/p>\n<pre><code class=\"language-sql\">SELECT StudentID,\n       FirstName, \n       AVG(Age) as AvgAge,\n       SUM(Grade) as SumGrade\nFROM Students_test\nGROUP BY StudentID, FirstName;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>AvgAge<\/th>\n<th>SumGrade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>15.0<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>14.0<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>16.0<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>15.0<\/td>\n<td>18<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>16. <strong>SQL Having: Filter rows after aggregating<\/strong><\/h2>\n<p>Consider the following SQL statement.<\/p>\n<pre><code class=\"language-sql\">SELECT StudentID,\n       FirstName, \n       AVG(Age) as Age,\n       SUM(Grade) as Grade\nFROM Students_test\nWHERE Grade &lt;= 10\nGROUP BY StudentID, FirstName;\n<\/code><\/pre>\n<p><strong>Now consider this with the &#8216;HAVING&#8217; clause<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT StudentID,\n       FirstName, \n       AVG(Age) as Age,\n       SUM(Grade) as SGrade\nFROM Students_test\nGROUP BY StudentID, FirstName\nHAVING SGrade &lt;= 100;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>Age<\/th>\n<th>SGrade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>15.0<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>14.0<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>16.0<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>15.0<\/td>\n<td>18<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><em>What is the difference between &#8220;WHERE&#8221; and &#8220;HAVING&#8221; in SQL?<\/em><\/strong><\/p>\n<p>This is a very important interview question.<\/p>\n<p>Answer:<\/p>\n<p>The <code>HAVING<\/code> clause is used in SQL to filter the results of a <code>GROUP BY<\/code> clause.<\/p>\n<p>While the <code>WHERE<\/code> clause can filter rows before they are aggregated, the <code>HAVING<\/code> clause filters the rows <em>after<\/em> they&#8217;ve been grouped and aggregated. This is the key distinction between the <code>WHERE<\/code> and <code>HAVING<\/code> clauses in SQL.<\/p>\n<pre><code class=\"language-sql\">SELECT StudentID,\n       FirstName, \n       AVG(Age) as Age,\n       SUM(Grade) as SGrade\nFROM Students_test\nGROUP BY StudentID, FirstName\nHAVING SGrade &lt;= 100;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>StudentID<\/th>\n<th>FirstName<\/th>\n<th>Age<\/th>\n<th>SGrade<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<td>15.0<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane<\/td>\n<td>14.0<\/td>\n<td>18<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Jim<\/td>\n<td>16.0<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Jack<\/td>\n<td>15.0<\/td>\n<td>18<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The column name in the HAVING clause refers to the name the comes <em>after<\/em> the grouping is done.<\/p>\n<h2>17. <strong>Joining Datasets<\/strong><\/h2>\n<p>Let&#8217;s say, you have two tables: Orders and Customer info. Both tables have the customerid in common. And you want to add Customer info to the orders data so you can see the details of each customer against every order.<\/p>\n<p>How do you achieve this?<\/p>\n<p>SQL Joins are used to combine rows from two or more tables based on a common column between them.<\/p>\n<p>This common column is often a primary key in one table that corresponds to a foreign key in another.<\/p>\n<h3>Types of SQL Joins<\/h3>\n<p>There are four main types of SQL Joins<\/p>\n<p>17(a) &#8211; <strong>INNER JOIN<\/strong>: Returns records that have matching values in both tables.<\/p>\n<p>17(b) &#8211; <strong>FULL (OUTER) JOIN<\/strong>: Returns all records when there is a match in either the left or the right table.<\/p>\n<p>17(c) &#8211; <strong>LEFT (OUTER) JOIN<\/strong>: Returns all records from the left table, and the matched records from the right table.<\/p>\n<p>17(d) &#8211; <strong>RIGHT (OUTER) JOIN<\/strong>: Returns all records from the right table, and the matched records from the left table.<\/p>\n<p>Let&#8217;s illustrate these concepts using a simple database with two tables, <code>Customers<\/code> and <code>Orders<\/code>.<\/p>\n<p><a href=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/joins.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/joins.png\" alt=\"\" width=\"945\" height=\"699\" class=\"aligncenter size-full wp-image-23477\" srcset=\"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/joins.png 945w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/joins-300x222.png 300w, https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/joins-768x568.png 768w\" sizes=\"(max-width: 945px) 100vw, 945px\" \/><\/a><\/p>\n<p>Let&#8217;s illustrate these concepts using a simple database with two tables, Customers and Orders.<\/p>\n<h3>Customer Table:<\/h3>\n<pre><code class=\"language-sql\">CREATE TABLE Customers (\n    CustomerID INT PRIMARY KEY,\n    Name VARCHAR(255)\n);\n\nINSERT INTO Customers (CustomerID, Name)\nVALUES (1, 'John'),\n       (2, 'Peter'),\n       (3, 'Mary'),\n       (4, 'Sally');\n<\/code><\/pre>\n<p>View <code>Customers<\/code> table<\/p>\n<pre><code class=\"language-sql\">select * from Customers;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>CustomerID<\/th>\n<th>Name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Peter<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Mary<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Sally<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Orders Table:<\/h3>\n<pre><code class=\"language-sql\">CREATE TABLE Orders (\n    OrderID INT PRIMARY KEY,\n    CustomerID INT,\n    Product VARCHAR(255)\n);\n\nINSERT INTO Orders (OrderID, CustomerID, Product)\nVALUES (1, 1, 'Apples'),\n       (2, 2, 'Bananas'),\n       (3, 4, 'Grapes'),\n       (4, 5, 'Oranges');\n<\/code><\/pre>\n<p>View <code>Orders<\/code> table<\/p>\n<pre><code class=\"language-sql\">select * from Orders;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>OrderID<\/th>\n<th>CustomerID<\/th>\n<th>Product<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>1<\/td>\n<td>Apples<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>2<\/td>\n<td>Bananas<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>4<\/td>\n<td>Grapes<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>5<\/td>\n<td>Oranges<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>17(a) &#8211; INNER JOIN<\/h2>\n<p>The <code>INNER JOIN<\/code> keyword selects records that have matching values in both tables.<\/p>\n<p>SQL Statement:<\/p>\n<pre><code class=\"language-sql\">SELECT Orders.*, Customers.Name \nFROM Customers\nINNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>OrderID<\/th>\n<th>CustomerID<\/th>\n<th>Product<\/th>\n<th>Name<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>1<\/td>\n<td>Apples<\/td>\n<td>John<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>2<\/td>\n<td>Bananas<\/td>\n<td>Peter<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>4<\/td>\n<td>Grapes<\/td>\n<td>Sally<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>17(b) &#8211; FULL JOIN<\/h2>\n<p>The <code>FULL JOIN<\/code> keyword returns all records when there is a match in the left (<code>Customers<\/code>) or the right (<code>Orders<\/code>) table. Records that do not have a match in the other table are shown as <code>NULL<\/code>.<\/p>\n<p>SQL Statement:<\/p>\n<pre><code class=\"language-sql\">SELECT Customers.Name, Orders.Product\nFROM Customers\nFULL OUTER JOIN Orders ON Customers.CustomerID = Orders.CustomerID;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>Name<\/th>\n<th>Product<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>John<\/td>\n<td>Apples<\/td>\n<\/tr>\n<tr>\n<td>Peter<\/td>\n<td>Bananas<\/td>\n<\/tr>\n<tr>\n<td>Mary<\/td>\n<td>None<\/td>\n<\/tr>\n<tr>\n<td>Sally<\/td>\n<td>Grapes<\/td>\n<\/tr>\n<tr>\n<td>None<\/td>\n<td>Oranges<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table>\n<thead>\n<tr>\n<th>Name<\/th>\n<th>Product<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>John<\/td>\n<td>Apples<\/td>\n<\/tr>\n<tr>\n<td>Peter<\/td>\n<td>Bananas<\/td>\n<\/tr>\n<tr>\n<td>Mary<\/td>\n<td>NULL<\/td>\n<\/tr>\n<tr>\n<td>Sally<\/td>\n<td>Grapes<\/td>\n<\/tr>\n<tr>\n<td>NULL<\/td>\n<td>Oranges<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-python\">%%html\n&lt;style&gt;\ntable {float:left}\n&lt;\/style&gt;\n<\/code><\/pre>\n<h2>17(c) &#8211; LEFT JOIN<\/h2>\n<p>The <code>LEFT JOIN<\/code> keyword returns all records from the left table (<code>Customers<\/code>), and the matched records from the right table (<code>Orders<\/code>). The result is <code>NULL<\/code> from the right side if there is no match.<\/p>\n<p>SQL Statement:<\/p>\n<pre><code class=\"language-sql\">SELECT Customers.Name, Orders.Product\nFROM Customers\nLEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>Name<\/th>\n<th>Product<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>John<\/td>\n<td>Apples<\/td>\n<\/tr>\n<tr>\n<td>Peter<\/td>\n<td>Bananas<\/td>\n<\/tr>\n<tr>\n<td>Mary<\/td>\n<td>None<\/td>\n<\/tr>\n<tr>\n<td>Sally<\/td>\n<td>Grapes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>17(d) &#8211; RIGHT JOIN<\/h2>\n<p>The <code>RIGHT JOIN<\/code> keyword returns all records from the right table (<code>Orders<\/code>), and the matched records from the left table (<code>Customers<\/code>). The result is NULL from the left side when there is no match.<\/p>\n<p>SQL Statement:<\/p>\n<pre><code class=\"language-sql\">SELECT Customers.Name, Orders.Product\nFROM Customers\nRIGHT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>Name<\/th>\n<th>Product<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>John<\/td>\n<td>Apples<\/td>\n<\/tr>\n<tr>\n<td>Peter<\/td>\n<td>Bananas<\/td>\n<\/tr>\n<tr>\n<td>Sally<\/td>\n<td>Grapes<\/td>\n<\/tr>\n<tr>\n<td>None<\/td>\n<td>Oranges<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table>\n<thead>\n<tr>\n<th>Name<\/th>\n<th>Product<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>John<\/td>\n<td>Apples<\/td>\n<\/tr>\n<tr>\n<td>Peter<\/td>\n<td>Bananas<\/td>\n<\/tr>\n<tr>\n<td>Sally<\/td>\n<td>Grapes<\/td>\n<\/tr>\n<tr>\n<td>NULL<\/td>\n<td>Oranges<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>18. Exercise 4: Joining Exercise<\/h2>\n<p>Try the following in MySQL Workbench on the Sakila Database<\/p>\n<ol>\n<li>From Sakila Database, create a new table that contains:\n<ul>\n<li>Film name<\/li>\n<li>Corresponding Actor name<\/li>\n<li>Release Year<\/li>\n<li>Rating<\/li>\n<li>Rental_Rate<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>Make sure none of the films get missed out in the result.<\/p>\n<p><em>Hint: Use Film table and Film Actor Table.<\/em><\/p>\n<ol>\n<li>What is the average rental rate for each Film actor?<\/li>\n<\/ol>\n<p>Note:<\/p>\n<ul>\n<li>The Sakila db is present as a default database in MySQL workbench.<br \/>\nIf not present, follow the instructions in the &#8216;Setup MySQL WorkBench&#8217; lesson above to set it up.<\/p>\n<\/li>\n<li>\n<p>Basically, you need to run the 2 SQL scripts inside &#8216;Sakila-db&#8217; directory: sakila-schema.sql, then, sakila-data.sql.<\/p>\n<\/li>\n<\/ul>\n<h2>19. <strong>SQL DateTime Operations<\/strong><\/h2>\n<p>SQL provides a set of functions for working with dates and times. These functions let you manipulate and format date and time values in your SQL queries.<\/p>\n<p>1) Extract the Date and time from a DateTime<br \/>\n2) Extract Year, Month, and Day<br \/>\n3) Extract Hours, Minutes, and Seconds<br \/>\n4) Increment and decrement Date Column by Days, Months and Years<br \/>\n5) Current date, time, and timestamp<br \/>\n6) Calculate Date Difference in Days, Years and Months<\/p>\n<pre><code class=\"language-sql\">CREATE TABLE Employees (\n    ID INT PRIMARY KEY,\n    Name VARCHAR(100),\n    HireDate DATETIME\n);\n\nINSERT INTO Employees (ID, Name, HireDate)\nVALUES \n(1, 'John Doe', '2017-03-12 09:30:10'),\n(2, 'Jane Smith', '2018-05-14 15:20:08'),\n(3, 'Emily Johnson', '2019-07-30 13:15:15'),\n(4, 'Robert Brown', '2020-10-20 10:00:35');\n\nSelect * from Employees;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>ID<\/th>\n<th>Name<\/th>\n<th>HireDate<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John Doe<\/td>\n<td>2017-03-12 09:30:10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane Smith<\/td>\n<td>2018-05-14 15:20:08<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Emily Johnson<\/td>\n<td>2019-07-30 13:15:15<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Robert Brown<\/td>\n<td>2020-10-20 10:00:35<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>1) Extract the Date and time from a DateTime<\/strong><\/p>\n<p>You can extract the date part from a DateTime using the <code>DATE()<\/code> function.<\/p>\n<pre><code class=\"language-sql\">SELECT *, \n      DATE(HireDate) AS 'Hire Date',\n      TIME(HireDate) AS 'Hire Time'\nFROM Employees;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>ID<\/th>\n<th>Name<\/th>\n<th>HireDate<\/th>\n<th>Hire Date<\/th>\n<th>Hire Time<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John Doe<\/td>\n<td>2017-03-12 09:30:10<\/td>\n<td>2017-03-12<\/td>\n<td>09:30:10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane Smith<\/td>\n<td>2018-05-14 15:20:08<\/td>\n<td>2018-05-14<\/td>\n<td>15:20:08<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Emily Johnson<\/td>\n<td>2019-07-30 13:15:15<\/td>\n<td>2019-07-30<\/td>\n<td>13:15:15<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Robert Brown<\/td>\n<td>2020-10-20 10:00:35<\/td>\n<td>2020-10-20<\/td>\n<td>10:00:35<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>2. Extract Year, Month, and Day<\/strong><\/p>\n<p>You can use the <code>strftime('%Y', date_col)<\/code>, <code>strftime('%m', date_col)<\/code>, and <code>strftime('%d', date_col)<\/code> functions to extract the respective date components from a DateTime value.<\/p>\n<pre><code class=\"language-sql\">SELECT *, \n    strftime('%Y', HireDate) as 'HireYear',\n    strftime('%m', HireDate) as 'HireMonth',\n    strftime('%d', HireDate) as 'HireDay'\nFROM Employees;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>ID<\/th>\n<th>Name<\/th>\n<th>HireDate<\/th>\n<th>HireYear<\/th>\n<th>HireMonth<\/th>\n<th>HireDay<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John Doe<\/td>\n<td>2017-03-12 09:30:10<\/td>\n<td>2017<\/td>\n<td>03<\/td>\n<td>12<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane Smith<\/td>\n<td>2018-05-14 15:20:08<\/td>\n<td>2018<\/td>\n<td>05<\/td>\n<td>14<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Emily Johnson<\/td>\n<td>2019-07-30 13:15:15<\/td>\n<td>2019<\/td>\n<td>07<\/td>\n<td>30<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Robert Brown<\/td>\n<td>2020-10-20 10:00:35<\/td>\n<td>2020<\/td>\n<td>10<\/td>\n<td>20<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>3. Extract Hours, Minutes, and Seconds<\/strong><\/p>\n<p>You can use the <code>strftime('%H', date_col)<\/code>, <code>strftime('%M', date_col)<\/code>, and <code>strftime('%S', date_col)<\/code> functions to extract the respective date components from a DateTime value.<\/p>\n<pre><code class=\"language-sql\">SELECT *, \n    strftime('%H', HireDate) as 'HireHour',\n    strftime('%M', HireDate) as 'HireMinute',\n    strftime('%S', HireDate) as 'HireSecond'\nFROM Employees;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>ID<\/th>\n<th>Name<\/th>\n<th>HireDate<\/th>\n<th>HireHour<\/th>\n<th>HireMinute<\/th>\n<th>HireSecond<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John Doe<\/td>\n<td>2017-03-12 09:30:10<\/td>\n<td>09<\/td>\n<td>30<\/td>\n<td>10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane Smith<\/td>\n<td>2018-05-14 15:20:08<\/td>\n<td>15<\/td>\n<td>20<\/td>\n<td>08<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Emily Johnson<\/td>\n<td>2019-07-30 13:15:15<\/td>\n<td>13<\/td>\n<td>15<\/td>\n<td>15<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Robert Brown<\/td>\n<td>2020-10-20 10:00:35<\/td>\n<td>10<\/td>\n<td>00<\/td>\n<td>35<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>4. Increment and decrement Date Column by Days, Months and Years<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT *,\n    DATETIME(HireDate, '+10 days') AS Add_Days,\n    DATETIME(HireDate, '-1 months') AS Add_Months,\n    DATETIME(HireDate, '+1 years') AS Add_Years\n\nFROM Employees;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>ID<\/th>\n<th>Name<\/th>\n<th>HireDate<\/th>\n<th>Add_Days<\/th>\n<th>Add_Months<\/th>\n<th>Add_Years<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John Doe<\/td>\n<td>2017-03-12 09:30:10<\/td>\n<td>2017-03-22 09:30:10<\/td>\n<td>2017-02-12 09:30:10<\/td>\n<td>2018-03-12 09:30:10<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane Smith<\/td>\n<td>2018-05-14 15:20:08<\/td>\n<td>2018-05-24 15:20:08<\/td>\n<td>2018-04-14 15:20:08<\/td>\n<td>2019-05-14 15:20:08<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Emily Johnson<\/td>\n<td>2019-07-30 13:15:15<\/td>\n<td>2019-08-09 13:15:15<\/td>\n<td>2019-06-30 13:15:15<\/td>\n<td>2020-07-30 13:15:15<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Robert Brown<\/td>\n<td>2020-10-20 10:00:35<\/td>\n<td>2020-10-30 10:00:35<\/td>\n<td>2020-09-20 10:00:35<\/td>\n<td>2021-10-20 10:00:35<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>5. Current date, time, and timestamp<\/strong>: <code>CURRENT_DATE<\/code>, <code>CURRENT_TIME<\/code>, <code>CURRENT_TIMESTAMP<\/code> functions will return the current date, time, and timestamp respectively.<\/p>\n<pre><code class=\"language-sql\">SELECT CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>CURRENT_DATE<\/th>\n<th>CURRENT_TIME<\/th>\n<th>CURRENT_TIMESTAMP<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2023-08-20<\/td>\n<td>07:27:36<\/td>\n<td>2023-08-20 07:27:36<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>6. Calculate Date Difference in Days, Years and Months<\/strong><\/p>\n<pre><code class=\"language-sql\">SELECT *,\nround(julianday('now') - julianday(HireDate),0) As Date_Diff_Days,\nround((julianday('now') - julianday(HireDate))\/30.44,0) As Date_Diff_Months,\nround((julianday('now') - julianday(HireDate))\/365.25,0) As Date_Diff_Years\nFROM Employees;\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>ID<\/th>\n<th>Name<\/th>\n<th>HireDate<\/th>\n<th>Date_Diff_Days<\/th>\n<th>Date_Diff_Months<\/th>\n<th>Date_Diff_Years<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>John Doe<\/td>\n<td>2017-03-12 09:30:10<\/td>\n<td>2352.0<\/td>\n<td>77.0<\/td>\n<td>6.0<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Jane Smith<\/td>\n<td>2018-05-14 15:20:08<\/td>\n<td>1924.0<\/td>\n<td>63.0<\/td>\n<td>5.0<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>Emily Johnson<\/td>\n<td>2019-07-30 13:15:15<\/td>\n<td>1482.0<\/td>\n<td>49.0<\/td>\n<td>4.0<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Robert Brown<\/td>\n<td>2020-10-20 10:00:35<\/td>\n<td>1034.0<\/td>\n<td>34.0<\/td>\n<td>3.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>SQL, short for Structured Query Language is a programming language used to communicate with databases and do various types of Data wrangling operations. This is an essential skillset for any type of Data related jobs. In this tutorial, let&#8217;s get started with the basics of SQL. 1. Why you should learn SQL? First, let&#8217;s understand [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":24005,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"default","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":"default","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-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[2091],"tags":[2104,2092,125],"class_list":["post-23465","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-mysql","tag-sql","tag-sqlite"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL Tutorial - A Simple and Intuitive Guide to the Structured Query Language - machinelearningplus<\/title>\n<meta name=\"description\" content=\"SQL, short for Structured Query Language is a programming language used to communicate with databases and do various types of Data wrangling operations. This is an essential skillset for any type of Data related jobs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/localhost:8080\/sql\/sql-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Tutorial - A Simple and Intuitive Guide to the Structured Query Language - machinelearningplus\" \/>\n<meta property=\"og:description\" content=\"SQL, short for Structured Query Language is a programming language used to communicate with databases and do various types of Data wrangling operations. This is an essential skillset for any type of Data related jobs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/localhost:8080\/sql\/sql-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"machinelearningplus\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/rtipaday\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-25T02:19:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-13T17:41:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/localhost:8080\/wp-content\/uploads\/2023\/08\/SQL-Tutorial.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Selva Prabhakaran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/R_Programming\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Selva Prabhakaran\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"30 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/\"},\"author\":{\"name\":\"Selva Prabhakaran\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/person\\\/510885c0515804366fa644c38258391e\"},\"headline\":\"SQL Tutorial &#8211; A Simple and Intuitive Guide to the Structured Query Language\",\"datePublished\":\"2023-08-25T02:19:49+00:00\",\"dateModified\":\"2023-09-13T17:41:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/\"},\"wordCount\":4625,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/SQL-Tutorial.png\",\"keywords\":[\"MYSQL\",\"SQL\",\"sqlite\"],\"articleSection\":[\"SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/\",\"url\":\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/\",\"name\":\"SQL Tutorial - A Simple and Intuitive Guide to the Structured Query Language - machinelearningplus\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/SQL-Tutorial.png\",\"datePublished\":\"2023-08-25T02:19:49+00:00\",\"dateModified\":\"2023-09-13T17:41:02+00:00\",\"description\":\"SQL, short for Structured Query Language is a programming language used to communicate with databases and do various types of Data wrangling operations. This is an essential skillset for any type of Data related jobs.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/localhost:8080\\\/sql\\\/sql-tutorial\\\/#primaryimage\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/SQL-Tutorial.png\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2023\\\/08\\\/SQL-Tutorial.png\",\"width\":1080,\"height\":1080,\"caption\":\"SQL Tutorial\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#website\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/\",\"name\":\"machinelearningplus\",\"description\":\"Learn Data Science (AI \\\/ ML) Online\",\"publisher\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/machinelearningplus.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#organization\",\"name\":\"machinelearningplus\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/MachineLearningplus-logo.svg\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/MachineLearningplus-logo.svg\",\"width\":348,\"height\":36,\"caption\":\"machinelearningplus\"},\"image\":{\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/#\\\/schema\\\/person\\\/510885c0515804366fa644c38258391e\",\"name\":\"Selva Prabhakaran\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/litespeed\\\/avatar\\\/a994280177da541405c016f593e86ea7.jpg?ver=1776968129\",\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/litespeed\\\/avatar\\\/a994280177da541405c016f593e86ea7.jpg?ver=1776968129\",\"contentUrl\":\"https:\\\/\\\/machinelearningplus.com\\\/wp-content\\\/litespeed\\\/avatar\\\/a994280177da541405c016f593e86ea7.jpg?ver=1776968129\",\"caption\":\"Selva Prabhakaran\"},\"description\":\"Selva is an experienced Data Scientist and leader, specializing in executing AI projects for large companies. Selva started machinelearningplus to make Data Science \\\/ ML \\\/ AI accessible to everyone. The website enjoys 4 Million+ readership. His courses, lessons, and videos are loved by hundreds of thousands of students and practitioners.\",\"sameAs\":[\"https:\\\/\\\/localhost:8080\\\/\",\"https:\\\/\\\/www.facebook.com\\\/rtipaday\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/R_Programming\"],\"url\":\"https:\\\/\\\/machinelearningplus.com\\\/author\\\/selva86\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Tutorial - A Simple and Intuitive Guide to the Structured Query Language - machinelearningplus","description":"SQL, short for Structured Query Language is a programming language used to communicate with databases and do various types of Data wrangling operations. This is an essential skillset for any type of Data related jobs.","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:\/\/localhost:8080\/sql\/sql-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"SQL Tutorial - A Simple and Intuitive Guide to the Structured Query Language - machinelearningplus","og_description":"SQL, short for Structured Query Language is a programming language used to communicate with databases and do various types of Data wrangling operations. This is an essential skillset for any type of Data related jobs.","og_url":"https:\/\/localhost:8080\/sql\/sql-tutorial\/","og_site_name":"machinelearningplus","article_author":"https:\/\/www.facebook.com\/rtipaday\/","article_published_time":"2023-08-25T02:19:49+00:00","article_modified_time":"2023-09-13T17:41:02+00:00","og_image":[{"width":1080,"height":1080,"url":"https:\/\/localhost:8080\/wp-content\/uploads\/2023\/08\/SQL-Tutorial.png","type":"image\/png"}],"author":"Selva Prabhakaran","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/R_Programming","twitter_misc":{"Written by":"Selva Prabhakaran","Est. reading time":"30 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/localhost:8080\/sql\/sql-tutorial\/#article","isPartOf":{"@id":"https:\/\/localhost:8080\/sql\/sql-tutorial\/"},"author":{"name":"Selva Prabhakaran","@id":"https:\/\/machinelearningplus.com\/#\/schema\/person\/510885c0515804366fa644c38258391e"},"headline":"SQL Tutorial &#8211; A Simple and Intuitive Guide to the Structured Query Language","datePublished":"2023-08-25T02:19:49+00:00","dateModified":"2023-09-13T17:41:02+00:00","mainEntityOfPage":{"@id":"https:\/\/localhost:8080\/sql\/sql-tutorial\/"},"wordCount":4625,"commentCount":0,"publisher":{"@id":"https:\/\/machinelearningplus.com\/#organization"},"image":{"@id":"https:\/\/localhost:8080\/sql\/sql-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/SQL-Tutorial.png","keywords":["MYSQL","SQL","sqlite"],"articleSection":["SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/localhost:8080\/sql\/sql-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/localhost:8080\/sql\/sql-tutorial\/","url":"https:\/\/localhost:8080\/sql\/sql-tutorial\/","name":"SQL Tutorial - A Simple and Intuitive Guide to the Structured Query Language - machinelearningplus","isPartOf":{"@id":"https:\/\/machinelearningplus.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/localhost:8080\/sql\/sql-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/localhost:8080\/sql\/sql-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/SQL-Tutorial.png","datePublished":"2023-08-25T02:19:49+00:00","dateModified":"2023-09-13T17:41:02+00:00","description":"SQL, short for Structured Query Language is a programming language used to communicate with databases and do various types of Data wrangling operations. This is an essential skillset for any type of Data related jobs.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/localhost:8080\/sql\/sql-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/localhost:8080\/sql\/sql-tutorial\/#primaryimage","url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/SQL-Tutorial.png","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2023\/08\/SQL-Tutorial.png","width":1080,"height":1080,"caption":"SQL Tutorial"},{"@type":"WebSite","@id":"https:\/\/machinelearningplus.com\/#website","url":"https:\/\/machinelearningplus.com\/","name":"machinelearningplus","description":"Learn Data Science (AI \/ ML) Online","publisher":{"@id":"https:\/\/machinelearningplus.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/machinelearningplus.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/machinelearningplus.com\/#organization","name":"machinelearningplus","url":"https:\/\/machinelearningplus.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/machinelearningplus.com\/#\/schema\/logo\/image\/","url":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2022\/05\/MachineLearningplus-logo.svg","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/uploads\/2022\/05\/MachineLearningplus-logo.svg","width":348,"height":36,"caption":"machinelearningplus"},"image":{"@id":"https:\/\/machinelearningplus.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/machinelearningplus.com\/#\/schema\/person\/510885c0515804366fa644c38258391e","name":"Selva Prabhakaran","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/machinelearningplus.com\/wp-content\/litespeed\/avatar\/a994280177da541405c016f593e86ea7.jpg?ver=1776968129","url":"https:\/\/machinelearningplus.com\/wp-content\/litespeed\/avatar\/a994280177da541405c016f593e86ea7.jpg?ver=1776968129","contentUrl":"https:\/\/machinelearningplus.com\/wp-content\/litespeed\/avatar\/a994280177da541405c016f593e86ea7.jpg?ver=1776968129","caption":"Selva Prabhakaran"},"description":"Selva is an experienced Data Scientist and leader, specializing in executing AI projects for large companies. Selva started machinelearningplus to make Data Science \/ ML \/ AI accessible to everyone. The website enjoys 4 Million+ readership. His courses, lessons, and videos are loved by hundreds of thousands of students and practitioners.","sameAs":["https:\/\/localhost:8080\/","https:\/\/www.facebook.com\/rtipaday\/","https:\/\/x.com\/https:\/\/twitter.com\/R_Programming"],"url":"https:\/\/machinelearningplus.com\/author\/selva86\/"}]}},"_links":{"self":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/posts\/23465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/comments?post=23465"}],"version-history":[{"count":0,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/posts\/23465\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/media\/24005"}],"wp:attachment":[{"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/media?parent=23465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/categories?post=23465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/machinelearningplus.com\/wp-json\/wp\/v2\/tags?post=23465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}