<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lucy Joan</title>
    <description>The latest articles on DEV Community by Lucy Joan (@lucy_joan_b56ae069a2a9f17).</description>
    <link>https://dev.to/lucy_joan_b56ae069a2a9f17</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2988400%2Fb69cd5e8-006f-4472-a047-f54240723c50.png</url>
      <title>DEV Community: Lucy Joan</title>
      <link>https://dev.to/lucy_joan_b56ae069a2a9f17</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lucy_joan_b56ae069a2a9f17"/>
    <language>en</language>
    <item>
      <title>Introduction to Supervised Machine Learning for Beginners</title>
      <dc:creator>Lucy Joan</dc:creator>
      <pubDate>Sat, 02 Aug 2025 08:10:15 +0000</pubDate>
      <link>https://dev.to/lucy_joan_b56ae069a2a9f17/introduction-to-supervised-machine-learning-for-beginners-105a</link>
      <guid>https://dev.to/lucy_joan_b56ae069a2a9f17/introduction-to-supervised-machine-learning-for-beginners-105a</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Machine learning might sound complex, but at its core, it’s simply about teaching computers to learn from examples — just like humans do. &lt;/p&gt;

&lt;p&gt;One of the most common and important ways machines learn is called supervised learning. This article will walk you through what supervised learning is, how it works, and why it matters — all explained in simple, beginner-friendly language.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Supervised Learning?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Supervised learning&lt;/strong&gt; is a type of machine learning where the model learns from a labeled dataset — meaning each input comes with a correct answer (or label).&lt;/p&gt;

&lt;p&gt;Supervised learning is like having a teacher guide you through a subject, giving you the questions and the correct answers so you can learn how to solve similar problems on your own.&lt;/p&gt;

&lt;p&gt;The “supervised” part means the machine is guided by examples.&lt;/p&gt;

&lt;p&gt;These examples come with labels (the correct answers), so the machine knows what the right outcome should be.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Imagine you’re learning to identify fruits.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You see a picture of a red, round fruit labeled “apple.”&lt;/li&gt;
&lt;li&gt;You see another picture of a long, yellow fruit labeled banana.”&lt;/li&gt;
&lt;li&gt;Over time, you can correctly identify an apple or a banana on your own because you’ve seen labeled examples.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;That’s exactly what supervised learning does — but with data instead of fruit pictures!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's use an example:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Suppose we want to teach a computer to distinguish between emails that are &lt;strong&gt;"Spam"&lt;/strong&gt; and those that are &lt;strong&gt;"Not Spam."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Data&lt;/strong&gt;: We gather a large collection of emails.&lt;br&gt;
&lt;strong&gt;The Labels&lt;/strong&gt;: For each email, we manually mark it as either "Spam" or "Not Spam."&lt;/p&gt;

&lt;p&gt;Our labeled dataset would look something like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Email 1&lt;/strong&gt;: "Congratulations! You've won a free vacation! Click here!" – &lt;strong&gt;Label: Spam&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Email 2:&lt;/strong&gt; "Meeting notes from yesterday's team sync." – &lt;strong&gt;Label: Not Spam&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Email 3:&lt;/strong&gt; "Claim your prize now! Limited time offer!" – &lt;strong&gt;Label: Spam&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Email 4:&lt;/strong&gt; "Your order has been shipped. Tracking number: XYZ123." – &lt;strong&gt;Label: Not Spam&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How the Computer Learns (The Magic Behind the Scenes)
&lt;/h3&gt;

&lt;p&gt;The computer then uses special algorithms (think of them as learning strategies) to look at all these examples. It starts to identify patterns and relationships between the content of the email and its label.&lt;/p&gt;

&lt;p&gt;For instance, it might notice that emails with words like "free," "win," "prize," "urgent," or a lot of exclamation marks are more likely to be spam. Conversely, emails with professional language, specific sender addresses, or order tracking information are more likely to be legitimate.&lt;/p&gt;

&lt;p&gt;The algorithm tries to build a model – which is essentially a set of rules or a mathematical function – that can accurately predict the label (Spam or Not Spam) for new, unseen emails.&lt;/p&gt;

&lt;p&gt;The goal is for the model to learn the relationship between input features and the target output so it can make predictions on new, unseen data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Importance of Supervised Machine Learning
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Learns from labeled data to make accurate predictions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Widely used in real-world tasks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spam detection&lt;/li&gt;
&lt;li&gt;Image and voice recognition&lt;/li&gt;
&lt;li&gt;Medical diagnosis&lt;/li&gt;
&lt;li&gt;Financial forecasting&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Easy to understand and implement — models learn like humans do, through examples.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;High accuracy and performance when trained with quality data.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Gives control over the learning process since outcomes (labels) are known.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Scalable and adaptable across many industries and use cases.&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Examples of Supervised Learning
&lt;/h2&gt;

&lt;p&gt;Supervised learning is all around us, even if we don’t notice it. Here are some relatable examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Email Spam Detection&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    Input: Words in your email&lt;/li&gt;
&lt;li&gt;    Output: Spam or not spam&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Loan Approval&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    Input: Your income, credit score, etc.&lt;/li&gt;
&lt;li&gt;    Output: Approve or reject your loan&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Medical Diagnosis&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    Input: Symptoms and test results&lt;/li&gt;
&lt;li&gt;    Output: Disease present or not&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Voice Assistants (like Siri or Alexa)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    Input: Your voice command&lt;/li&gt;
&lt;li&gt;    Output: Translated into text or action&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Image Recognition&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;    Input: Photo of a cat&lt;/li&gt;
&lt;li&gt;    Output: Label “cat”&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Two Main Types of Supervised Learning
&lt;/h2&gt;

&lt;p&gt;Supervised learning problems generally fall into two main categories:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Classification:
&lt;/h3&gt;

&lt;p&gt;Predicting a category or a discrete class.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The model learns to answer "What kind of thing is this?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is this email Spam or Not Spam? (Two classes)&lt;/li&gt;
&lt;li&gt;Is this picture a Cat, a Dog, or a Bird? (Multiple classes)&lt;/li&gt;
&lt;li&gt;Will this customer churn (leave) or not? (Two classes)
Think of it as: Sorting things into buckets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common Classification Algorithms:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logistic Regression&lt;/li&gt;
&lt;li&gt;Decision Tree Classifier&lt;/li&gt;
&lt;li&gt;Random Forest Classifier&lt;/li&gt;
&lt;li&gt;Support Vector Machine (SVM)&lt;/li&gt;
&lt;li&gt;K-Nearest Neighbors (KNN)&lt;/li&gt;
&lt;li&gt;Naive Bayes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output Type:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Discrete&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Example: ["Yes", "No"], [0, 1], ["Dog", "Cat", "Bird"]&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Algorithm&lt;/th&gt;
&lt;th&gt;Definition&lt;/th&gt;
&lt;th&gt;When to Use&lt;/th&gt;
&lt;th&gt;Python Import Example&lt;/th&gt;
&lt;th&gt;Notable Features&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Logistic Regression&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Predicts probability of class membership using a sigmoid function.&lt;/td&gt;
&lt;td&gt;For binary classification (e.g., spam vs not spam).&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.linear_model import LogisticRegression&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Fast, interpretable, works well with linear data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Decision Tree Classifier&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Creates decision rules in a tree structure to classify data.&lt;/td&gt;
&lt;td&gt;When interpretability and simple logic are needed.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.tree import DecisionTreeClassifier&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Easy to visualize, can overfit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Random Forest Classifier&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses many decision trees and averages results for better accuracy.&lt;/td&gt;
&lt;td&gt;When accuracy is more important than interpretability.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.ensemble import RandomForestClassifier&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Powerful, reduces overfitting, handles non-linearity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Support Vector Machine (SVM)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Finds a hyperplane that best separates classes.&lt;/td&gt;
&lt;td&gt;When classes are well separated or data is high-dimensional.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.svm import SVC&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Works well in small datasets, robust to outliers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;K-Nearest Neighbors (KNN)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Classifies based on the majority of k nearest neighbors.&lt;/td&gt;
&lt;td&gt;When the data is low-dimensional and relationships are local.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.neighbors import KNeighborsClassifier&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Simple, no training phase, memory intensive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Naive Bayes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses Bayes' Theorem assuming feature independence.&lt;/td&gt;
&lt;td&gt;When working with text (e.g., sentiment or spam detection).&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.naive_bayes import MultinomialNB&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Very fast, good baseline for text classification&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  2. Regression:
&lt;/h3&gt;

&lt;p&gt;Predicting a continuous numerical value.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The model learns to answer "How much?" or "What’s the value?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What will the price of a house be based on its size, location, and number of rooms?&lt;/li&gt;
&lt;li&gt;How many sales will a store make next month based on advertising spend and seasonality?&lt;/li&gt;
&lt;li&gt;What will the temperature be tomorrow?
Think of it as: Predicting a number on a scale.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Common Regression Algorithms:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linear Regression&lt;/li&gt;
&lt;li&gt;Ridge Regression&lt;/li&gt;
&lt;li&gt;Lasso Regression&lt;/li&gt;
&lt;li&gt;Decision Tree Regressor&lt;/li&gt;
&lt;li&gt;Random Forest Regressor&lt;/li&gt;
&lt;li&gt;Support Vector Regressor (SVR)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Output Type:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Continuous&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Example: 23.7, 1500, -4.8&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Algorithm&lt;/th&gt;
&lt;th&gt;Definition&lt;/th&gt;
&lt;th&gt;When to Use&lt;/th&gt;
&lt;th&gt;Python Import Example&lt;/th&gt;
&lt;th&gt;Notable Features&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Linear Regression&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Predicts a target value by fitting a straight line through the data.&lt;/td&gt;
&lt;td&gt;When the relationship between variables is linear.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.linear_model import LinearRegression&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Simple, fast, interpretable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Ridge Regression&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Linear regression with L2 regularization to reduce overfitting.&lt;/td&gt;
&lt;td&gt;When you want to penalize large coefficients but keep all variables.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.linear_model import Ridge&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Adds stability by shrinking coefficients&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Lasso Regression&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Linear regression with L1 regularization for feature selection.&lt;/td&gt;
&lt;td&gt;When you want to shrink some features to zero (ignore them).&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.linear_model import Lasso&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Useful for sparse data or reducing model complexity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Decision Tree Regressor&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Splits data into branches and predicts a value at the leaves.&lt;/td&gt;
&lt;td&gt;When the data has non-linear relationships or clear decision boundaries.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.tree import DecisionTreeRegressor&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Easy to understand, can overfit without pruning&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Random Forest Regressor&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;An ensemble of decision trees for regression.&lt;/td&gt;
&lt;td&gt;When you want accurate predictions and want to avoid overfitting.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.ensemble import RandomForestRegressor&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Handles non-linearities well, robust and powerful&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Support Vector Regressor (SVR)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Uses support vectors to fit a curve within a margin of tolerance.&lt;/td&gt;
&lt;td&gt;When the data is high-dimensional or not linearly separable.&lt;/td&gt;
&lt;td&gt;&lt;code&gt;from sklearn.svm import SVR&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Works well with complex, small datasets&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  The Machine Learning Recipe: Step-by-Step Guide to Supervised Learning
&lt;/h3&gt;

&lt;p&gt;Supervised learning follows a structured process — just like following a recipe. Here's how you build a machine learning model from scratch:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Collect Data&lt;/strong&gt;&lt;br&gt;
Gather examples that include both input features and the correct answers (labels).&lt;/p&gt;

&lt;p&gt;Example: A list of emails labeled as “Spam” or “Not Spam.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Clean the Data&lt;/strong&gt;&lt;br&gt;
Fix missing values, remove duplicates, and correct errors to ensure data quality.&lt;/p&gt;

&lt;p&gt;Clean data = better learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Split the Data&lt;/strong&gt;&lt;br&gt;
Divide your dataset into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Training Set (usually 70–80%) – used to teach the model&lt;/li&gt;
&lt;li&gt;Test Set (20–30%) – used to see how well the model learned&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This prevents the model from just memorizing everything.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Choose the Right Model&lt;/strong&gt;&lt;br&gt;
Pick an algorithm that suits your problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Classification (e.g., Logistic Regression)&lt;/li&gt;
&lt;li&gt;Regression (e.g., Linear Regression)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Preprocess the Data&lt;/strong&gt;&lt;br&gt;
Prepare the features so the model can understand them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Normalize/standardize numeric values&lt;/li&gt;
&lt;li&gt;Encode categories (like Yes/No → 1/0)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. Train the Model&lt;/strong&gt;&lt;br&gt;
Feed the training data into the model so it can learn patterns between inputs and outputs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Test the Model&lt;/strong&gt;&lt;br&gt;
Use the test data to check how well the model performs on unseen examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Evaluate Performance&lt;/strong&gt;&lt;br&gt;
Use metrics to measure accuracy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For classification: Accuracy, Precision, F1-Score&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;What it Means&lt;/th&gt;
&lt;th&gt;Use When&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Accuracy&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;% of correct predictions&lt;/td&gt;
&lt;td&gt;Classes are balanced&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Precision&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Of those predicted &lt;strong&gt;positive&lt;/strong&gt;, how many were correct?&lt;/td&gt;
&lt;td&gt;Cost of false positives is high (e.g., email spam)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Recall&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Of all actual &lt;strong&gt;positives&lt;/strong&gt;, how many did we find?&lt;/td&gt;
&lt;td&gt;Cost of false negatives is high (e.g., disease)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;F1-Score&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Harmonic mean of precision &amp;amp; recall&lt;/td&gt;
&lt;td&gt;When you want balance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Confusion Matrix&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Shows TP, FP, FN, TN&lt;/td&gt;
&lt;td&gt;To visualize classification mistakes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;True Positive(TP) - Model correctly predicted Positive (and it actually is Positive).
False Positive(FP) - Model predicted Positive, but it's actually Negative (aka "False Alarm").
False Negative(FN) - Model predicted Negative, but it's actually Positive (aka "Missed it").
True Negative(TN) - Model correctly predicted Negative (and it actually is Negative)             |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For regression: Mean Squared Error (MSE), R² Score&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;What it Means&lt;/th&gt;
&lt;th&gt;Use When&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mean Absolute Error (MAE)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Average of absolute errors&lt;/td&gt;
&lt;td&gt;Easy to understand&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Mean Squared Error (MSE)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Penalizes big errors more&lt;/td&gt;
&lt;td&gt;Common and popular&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Root Mean Squared Error (RMSE)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Square root of MSE&lt;/td&gt;
&lt;td&gt;Same units as target&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;R² Score (R-squared)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;How much variance is explained&lt;/td&gt;
&lt;td&gt;1 is perfect, 0 is bad&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;9. Tune the Model (Optimize)&lt;/strong&gt;&lt;br&gt;
Adjust the model’s settings (called hyperparameters) or try different algorithms to improve results and fix:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Underfitting – Model is too simple&lt;/li&gt;
&lt;li&gt;Overfitting – Model memorized training data too well&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;10. Deploy the Model&lt;/strong&gt;&lt;br&gt;
Once it performs well, integrate the model into a real system — like predicting spam emails or product prices in an app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. Monitor and Update&lt;/strong&gt;&lt;br&gt;
Track how the model performs over time. As new data comes in, you may need to retrain or update the model to keep it accurate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Errors in Supervised ML
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Error Type&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;How to Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Underfitting&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Model is too simple&lt;/td&gt;
&lt;td&gt;Use a more complex model or add features&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Overfitting&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Model memorized instead of learning&lt;/td&gt;
&lt;td&gt;Simplify model or use more data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Bias&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Model is unfair or always wrong in one way&lt;/td&gt;
&lt;td&gt;Use fairer data, tune model&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Variance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Model changes too much on small changes&lt;/td&gt;
&lt;td&gt;Use regularization or simpler model&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;The main parts of machine learning include data, features, a model, and an algorithm. The process starts by feeding data into the model, which is trained using the algorithm. After training, the model is tested and evaluated. Once it's accurate enough, it can make predictions on new, unseen data.&lt;/p&gt;

&lt;p&gt;Think of it like teaching someone to bake:&lt;br&gt;
You gather ingredients (data), follow a recipe (algorithm), practice baking (training), test how good the cookies are (evaluation), and eventually, bake confidently (prediction).&lt;/p&gt;

&lt;p&gt;Supervised learning is just one branch of machine learning. There’s also unsupervised learning, which finds patterns in data without labels (like grouping similar customers), and reinforcement learning, where an agent learns by trial and error (like teaching a robot to walk).&lt;/p&gt;

&lt;p&gt;Check out my github: &lt;a href="https://github.com/Lucy23-2024" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>beginners</category>
      <category>openai</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Introduction to SQL Using PostreSQL</title>
      <dc:creator>Lucy Joan</dc:creator>
      <pubDate>Sat, 26 Apr 2025 13:44:52 +0000</pubDate>
      <link>https://dev.to/lucy_joan_b56ae069a2a9f17/introduction-to-sql-using-postresql-3l7p</link>
      <guid>https://dev.to/lucy_joan_b56ae069a2a9f17/introduction-to-sql-using-postresql-3l7p</guid>
      <description>&lt;h2&gt;
  
  
  PostgreSQL for Absolute Beginners: Your First Step into Data Management
&lt;/h2&gt;

&lt;p&gt;Imagine managing millions of Instagram posts or handling customer orders worldwide without confusion.&lt;br&gt;
Behind the scenes, a powerful tool called SQL (Structured Query Language) makes it all possible. In this beginner’s guide, we’ll walk you through PostgreSQL, one of the world’s most popular database systems, and help you write your first SQL commands.&lt;/p&gt;
&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;p&gt;. What is SQL?&lt;br&gt;
. How to set up PostreSQL&lt;br&gt;
. Basic database concepts (schemas, tables, rows)&lt;br&gt;
. Writing your first SQL queries&lt;br&gt;
. A mini hands-on project&lt;br&gt;
. Pro tips and next steps&lt;/p&gt;

&lt;p&gt;&lt;a id="#intro"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction to SQL?
&lt;/h2&gt;

&lt;p&gt;SQL (structured query language) is a programming language for storing and processing information in relational database management systems (stores information in tabular form, with rows and columns).&lt;/p&gt;

&lt;p&gt;It is used extensively for storing, manipulating and retrieving data in systems such as MySQL, PostgreSQL etc.&lt;/p&gt;

&lt;p&gt;You can use SQL statements to store, update, remove, search, and retrieve information from the database - making it essential for tasks like data analysis, software development, and database administration. &lt;/p&gt;

&lt;p&gt;You can also use SQL to maintain and optimize database performance.&lt;br&gt;
Whether you're building applications, generating reports, or analysing big data, SQL provides the tools needed to interact with complex datasets quickly and efficiently. Thanks to its versatility and widespread adoption, SQL remains one of the most important skills in today’s data-driven world.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In this article, we will focus on PostgreSQL, a powerful and widely-used open-source relational database management system (RDBMS). You will learn what makes PostgreSQL a preferred choice for developers, data analysts, and businesses managing complex data. In our next article, we will provide a step-by-step guide on how to download, install, and set up PostgreSQL on your computer, so you can start building and managing your own databases.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a id="#point-one"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Set Up PostgreSQL: Step-by-Step Guide for Beginners
&lt;/h2&gt;

&lt;p&gt;Setting up PostgreSQL correctly is essential for creating secure and high-performing databases. In this guide, we’ll cover everything you need to know to download, install, and configure PostgreSQL on your machine, whether you are using Windows, macOS, or Linux.&lt;/p&gt;

&lt;p&gt;Step 1: Download PostgreSQL&lt;br&gt;
. Go to the official PostgreSQL website: &lt;a href="https://www.postgresql.org/download/" rel="noopener noreferrer"&gt;https://www.postgresql.org/download/&lt;/a&gt;&lt;br&gt;
. Choose your operating system (Windows, macOS, Linux).&lt;br&gt;
. Download the latest stable version of PostgreSQL.&lt;/p&gt;

&lt;p&gt;Step 2: Install PostgreSQL&lt;/p&gt;

&lt;p&gt;For Windows:&lt;br&gt;
. Open the downloaded installer.&lt;br&gt;
. Follow the setup wizard.&lt;br&gt;
. Choose an installation directory.&lt;br&gt;
. Set a password for the PostgreSQL superuser (postgres).&lt;br&gt;
. Select the default port (5432) unless you need to change it.&lt;br&gt;
. Complete the installation.&lt;/p&gt;

&lt;p&gt;For macOS:&lt;br&gt;
Install using the PostgreSQL installer package or use Homebrew&lt;/p&gt;

&lt;p&gt;For Linux:&lt;br&gt;
Install using your package manager&lt;/p&gt;

&lt;p&gt;Step 3: Set Up PostgreSQL&lt;br&gt;
. Verify the installation.&lt;br&gt;
. Open pgAdmin (the PostgreSQL management tool) or connect via command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;psql &lt;span class="nt"&gt;-U&lt;/span&gt; postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a id="#point-two"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic database concepts
&lt;/h2&gt;

&lt;p&gt;Before you dive into writing SQL queries, it’s important to understand the core building blocks of databases. These basic concepts will help you feel more confident as you start creating and managing your own data structures.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Term&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Database&lt;/td&gt;
&lt;td&gt;A collection of organized data stored electronically&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Schema&lt;/td&gt;
&lt;td&gt;A logical container that holds tables, views, and other database objects. Think of it like a folder that keeps everything organized&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Table&lt;/td&gt;
&lt;td&gt;A structured set of data organized into rows and columns, similar to a spreadsheet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Row&lt;/td&gt;
&lt;td&gt;A single record inside a table, containing related data for one item&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Column&lt;/td&gt;
&lt;td&gt;A specific attribute or field that holds one type of data, such as a name, email, or date of enrollment&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Visual Example of a Database Structure&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;school&lt;/span&gt;
&lt;span class="err"&gt;│&lt;/span&gt;
&lt;span class="err"&gt;└──&lt;/span&gt; &lt;span class="k"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt;
    &lt;span class="err"&gt;│&lt;/span&gt;
    &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="k"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;students&lt;/span&gt;
    &lt;span class="err"&gt;│&lt;/span&gt;    &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="err"&gt;│&lt;/span&gt;    &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="err"&gt;│&lt;/span&gt;    &lt;span class="err"&gt;├──&lt;/span&gt; &lt;span class="n"&gt;enrollment_date&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;column&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;p&gt;Database: &lt;code&gt;school&lt;/code&gt; is the main database.&lt;/p&gt;

&lt;p&gt;Schema: &lt;code&gt;public&lt;/code&gt; groups related tables.&lt;/p&gt;

&lt;p&gt;Table: &lt;code&gt;students&lt;/code&gt; stores information about students.&lt;/p&gt;

&lt;p&gt;Columns: &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, and &lt;code&gt;enrollment_date&lt;/code&gt; are the fields capturing each student's data.&lt;/p&gt;

&lt;p&gt;&lt;a id="#point-three"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Your first SQL queries
&lt;/h2&gt;

&lt;p&gt;Now that you understand the basic building blocks of databases, it’s time to write your first SQL queries! SQL (Structured Query Language) is the tool you’ll use to interact with your database — to create tables, insert data, and retrieve information.&lt;/p&gt;

&lt;p&gt;Here are a few simple SQL commands to get you started:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create a Database
&lt;/h2&gt;

&lt;p&gt;First, you need a database to store your tables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;hr_system&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE DATABASE&lt;/code&gt; creates a new database named &lt;code&gt;hr_system&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is where all your data and tables will live.&lt;/p&gt;

&lt;p&gt;✅ Tip: After creating it, make sure to connect to the hr_system database before proceeding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="k"&gt;c&lt;/span&gt; &lt;span class="n"&gt;hr_system&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Create a Schema
&lt;/h2&gt;

&lt;p&gt;A schema helps organize your tables inside the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;SCHEMA&lt;/span&gt; &lt;span class="n"&gt;hr_schema&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE SCHEMA&lt;/code&gt; creates a container (folder-like structure) for your tables.&lt;/p&gt;

&lt;p&gt;It’s especially useful when you have many tables or want to separate different areas of your system.&lt;/p&gt;

&lt;p&gt;✅ Tip: You can also skip this if you want to use the default &lt;code&gt;public&lt;/code&gt; schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Create a Table
&lt;/h2&gt;

&lt;p&gt;To create a new table for storing student information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;hr_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HR_DATASET&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;employee_id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;department&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="nb"&gt;CHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;gender&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;enrollment_date&lt;/span&gt; &lt;span class="nb"&gt;DATE&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;CREATE TABLE hr_schema.HR_DATASET&lt;/code&gt; means you’re creating the table &lt;code&gt;HR_DATASET&lt;/code&gt; inside &lt;code&gt;hr_schema&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;employee_id&lt;/code&gt; is a unique, auto-incremented number for each employee.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;first_name&lt;/code&gt; and &lt;code&gt;last_name&lt;/code&gt; store the employee’s name.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;department&lt;/code&gt; indicates which department the employee belongs to.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;age&lt;/code&gt; is stored as a fixed-length character field.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gender&lt;/code&gt; and &lt;code&gt;enrollment_date&lt;/code&gt; capture additional details about the employee.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Insert Data into the Table
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;HR_DATASET&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;gender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;enrollment_date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'John'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Doe'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Finance'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'29'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Male'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'2024-09-01'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;INSERT INTO&lt;/code&gt; tells SQL where to add the new record.&lt;/p&gt;

&lt;p&gt;We provide values for &lt;code&gt;first_name&lt;/code&gt;, &lt;code&gt;last_name&lt;/code&gt;, &lt;code&gt;department&lt;/code&gt;, &lt;code&gt;age&lt;/code&gt;, &lt;code&gt;gender&lt;/code&gt;, and &lt;code&gt;enrollment_date&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Retrieve Data with SELECT
&lt;/h2&gt;

&lt;p&gt;To view all the records in the table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;HR_DATASET&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT *&lt;/code&gt; fetches all columns and all rows from the &lt;code&gt;HR_DATASET&lt;/code&gt; table.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Update Data
&lt;/h2&gt;

&lt;p&gt;If you need to update an employee's department:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;HR_DATASET&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Human Resources'&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;employee_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;UPDATE&lt;/code&gt; modifies existing records.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SET&lt;/code&gt; changes the value of a specific column.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WHERE&lt;/code&gt; ensures only the correct record is updated.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Delete Data
&lt;/h2&gt;

&lt;p&gt;To remove an employee from the table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;HR_DATASET&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;employee_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DELETE FROM&lt;/code&gt; removes specific data.&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;WHERE&lt;/code&gt; is important to avoid deleting all records accidentally.&lt;/p&gt;

&lt;p&gt;&lt;a id="#point-four"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Hands-on Project: Customer Order Management System
&lt;/h2&gt;

&lt;p&gt;In this project, you will create a simple Customer Order Management System. This system will help manage customer details, the products they purchase, and the orders they place. The goal is to create a database that can handle customer and order data effectively.&lt;/p&gt;

&lt;p&gt;Project Objective:&lt;br&gt;
You will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a database and schema.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create tables for customers, orders, and products.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Insert records.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Query the data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update and delete records.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Step 1: Create the Database
&lt;/h2&gt;

&lt;p&gt;Create a database called &lt;code&gt;customer_orders_system&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;DATABASE&lt;/span&gt; &lt;span class="n"&gt;customer_orders_system&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: This database will hold all the data for customer orders, including customer details, products, and orders.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create the Schema
&lt;/h2&gt;

&lt;p&gt;Create a schema called sales_schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;SCHEMA&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: Organize your data into a dedicated schema for the sales system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Create the Customers Table
&lt;/h2&gt;

&lt;p&gt;Now, create a table to store customer information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;last_name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;phone&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;address&lt;/span&gt; &lt;span class="nb"&gt;TEXT&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: This table will store customer details, such as name, email, phone number, and address.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Create the Products Table
&lt;/h2&gt;

&lt;p&gt;Next, create a table to store product information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;product_name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;stock_quantity&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: This table holds the product details — name, price, and available stock.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Create the Orders Table
&lt;/h2&gt;

&lt;p&gt;Create a table to store order details:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;order_date&lt;/span&gt; &lt;span class="nb"&gt;DATE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;total_amount&lt;/span&gt; &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: This table holds the orders placed by customers. It includes references to the customer table and stores the total amount of the order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Create the Order Items Table
&lt;/h2&gt;

&lt;p&gt;Since an order can contain multiple products, we need a table to link products to orders:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_items&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;order_item_id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;subtotal&lt;/span&gt; &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: This table stores the relationship between orders and the products within each order, including the quantity and subtotal for each product in the order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Insert Customer Records
&lt;/h2&gt;

&lt;p&gt;Now, insert some customer records into the customers table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Johnson'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'alice.johnson@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'123-456-7890'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'123 Elm Street'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Smith'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'bob.smith@example.com'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'234-567-8901'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'456 Oak Avenue'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: Add some customers to the system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Insert Product Records
&lt;/h2&gt;

&lt;p&gt;Now, insert some products into the products table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stock_quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Laptop'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Smartphone'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Tablet'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: Add products that customers can purchase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 9: Insert Orders
&lt;/h2&gt;

&lt;p&gt;Let’s now create some orders for the customers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'2025-04-01'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1500&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'2025-04-02'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;800&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: Create orders for Alice and Bob.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 10: Insert Order Items
&lt;/h2&gt;

&lt;p&gt;Add products to each order by inserting records into the order_items table. Let’s assume Alice bought a Laptop and a Tablet, while Bob bought a Smartphone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_items&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subtotal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;  &lt;span class="c1"&gt;-- Alice bought 1 Laptop&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;  &lt;span class="c1"&gt;-- Alice bought 1 Tablet&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;-- Bob bought 1 Smartphone&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: Link the products to the orders, including the quantity and subtotal for each item.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 11: Retrieve Data
&lt;/h2&gt;

&lt;p&gt;Let’s query the system to retrieve records for all tables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_items&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 12: Update Product Stock
&lt;/h2&gt;

&lt;p&gt;Let’s say Bob purchased the last smartphone. Update the stock quantity for the smartphone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;products&lt;/span&gt;
&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;stock_quantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stock_quantity&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;product_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Smartphone'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: Learn how to update product inventory after an order is placed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 14: Delete an Order
&lt;/h2&gt;

&lt;p&gt;If you need to remove an order, say Alice’s order with ID 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;order_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objective: Practice deleting records from the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 15: Review and Reflection
&lt;/h2&gt;

&lt;p&gt;Once you’ve completed this mini project:&lt;/p&gt;

&lt;p&gt;Review the relationships between customers, orders, products, and order items.&lt;/p&gt;

&lt;p&gt;Experiment by adding more customers, products, and orders.&lt;/p&gt;

&lt;p&gt;Reflect on how your system is tracking orders and inventory.&lt;/p&gt;

&lt;p&gt;&lt;a id="#point-five"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pro tips: Understanding SQL Data Types and Constraints
&lt;/h2&gt;

&lt;p&gt;When working with SQL, it’s essential to understand the various data types and constraints to properly define your tables and columns. Here’s a quick summary of some commonly used SQL data types and constraints:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Term&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Range/Details&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Integer&lt;/td&gt;
&lt;td&gt;&lt;code&gt;INT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores whole numbers&lt;/td&gt;
&lt;td&gt;&lt;code&gt;age INT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Typically -2,147,483,648 to 2,147,483,647&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Large Integer&lt;/td&gt;
&lt;td&gt;&lt;code&gt;BIGINT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores large whole numbers&lt;/td&gt;
&lt;td&gt;&lt;code&gt;employee_id BIGINT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Up to 9,223,372,036,854,775,807&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Character&lt;/td&gt;
&lt;td&gt;&lt;code&gt;VARCHAR(n)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores variable-length strings&lt;/td&gt;
&lt;td&gt;&lt;code&gt;first_name VARCHAR(100)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Max length varies (commonly up to 255 characters)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fixed Character&lt;/td&gt;
&lt;td&gt;&lt;code&gt;CHAR(n)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores fixed-length strings (padded with spaces if shorter)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;gender CHAR(10)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Max length typically 255 characters&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Large Text&lt;/td&gt;
&lt;td&gt;&lt;code&gt;TEXT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores large strings of text (no predefined length)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;address TEXT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Varies by database (e.g., 65,535 characters in MySQL)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Decimal&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DECIMAL(p, s)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores fixed-point numbers, precision (&lt;code&gt;p&lt;/code&gt;) and scale (&lt;code&gt;s&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;price DECIMAL(10, 2)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Max precision typically 65 digits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Floating Point&lt;/td&gt;
&lt;td&gt;&lt;code&gt;FLOAT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores floating-point numbers with approximate precision&lt;/td&gt;
&lt;td&gt;&lt;code&gt;rating FLOAT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Range typically -1.0E+308 to 1.0E+308&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Date&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DATE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores date values (year, month, day)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;enrollment_date DATE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Format: &lt;code&gt;YYYY-MM-DD&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Time&lt;/td&gt;
&lt;td&gt;&lt;code&gt;TIME&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores time values (hours, minutes, seconds)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;order_time TIME&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Format: &lt;code&gt;HH:MM:SS&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Datetime&lt;/td&gt;
&lt;td&gt;&lt;code&gt;DATETIME&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores both date and time values&lt;/td&gt;
&lt;td&gt;&lt;code&gt;order_timestamp DATETIME&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Format: &lt;code&gt;YYYY-MM-DD HH:MM:SS&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Timestamp&lt;/td&gt;
&lt;td&gt;&lt;code&gt;TIMESTAMP&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores date and time with automatic updates when records are modified&lt;/td&gt;
&lt;td&gt;&lt;code&gt;created_at TIMESTAMP&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Auto-updates on insert/update&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Boolean&lt;/td&gt;
&lt;td&gt;&lt;code&gt;BOOLEAN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Stores true/false values&lt;/td&gt;
&lt;td&gt;&lt;code&gt;is_active BOOLEAN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Typically &lt;code&gt;TRUE&lt;/code&gt; or &lt;code&gt;FALSE&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Primary Key&lt;/td&gt;
&lt;td&gt;&lt;code&gt;PRIMARY KEY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Uniquely identifies records in a table&lt;/td&gt;
&lt;td&gt;&lt;code&gt;employee_id SERIAL PRIMARY KEY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Must be unique, cannot be NULL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Foreign Key&lt;/td&gt;
&lt;td&gt;&lt;code&gt;FOREIGN KEY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Creates a relationship between tables by referencing another table's primary key&lt;/td&gt;
&lt;td&gt;&lt;code&gt;customer_id INT REFERENCES customers(customer_id)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ensures referential integrity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Not Null&lt;/td&gt;
&lt;td&gt;&lt;code&gt;NOT NULL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ensures that a column cannot contain a &lt;code&gt;NULL&lt;/code&gt; value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;first_name VARCHAR(100) NOT NULL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Column must always have a value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Auto-Increment&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SERIAL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Automatically generates unique numbers for new records (commonly used for primary keys)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;employee_id SERIAL PRIMARY KEY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Similar to &lt;code&gt;AUTO_INCREMENT&lt;/code&gt; in MySQL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unique&lt;/td&gt;
&lt;td&gt;&lt;code&gt;UNIQUE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ensures all values in a column are distinct&lt;/td&gt;
&lt;td&gt;&lt;code&gt;email VARCHAR(100) UNIQUE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;No duplicate values allowed&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Where To Go From Here
&lt;/h2&gt;

&lt;p&gt;Now that you've learned the basics of SQL, it’s time to take your skills to the next level. Here’s what you should focus on next:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Learn SQL JOINs — Master how to combine data from multiple tables using SQL JOINs like INNER JOIN, LEFT JOIN, and RIGHT JOIN. This is essential for working with relational databases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand SQL Indexes — Learning how SQL indexes work will help you optimize your database performance and make your queries run faster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Work on SQL Project Ideas — The best way to improve your SQL skills is through practice. Start by building small projects like:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- A blog database to manage posts, authors, and comments

- An inventory management system to track products, stock levels, and 
  suppliers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Lastly, Consistent SQL practice and real-world projects will help you master database management and prepare you for advanced topics like stored procedures and database optimization.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>datascience</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
