<?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: Brayan Wafula</title>
    <description>The latest articles on DEV Community by Brayan Wafula (@brayan_wafula_2c36816f4c3).</description>
    <link>https://dev.to/brayan_wafula_2c36816f4c3</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4071776%2F427db318-0684-4c17-bdde-a70b82067ce2.png</url>
      <title>DEV Community: Brayan Wafula</title>
      <link>https://dev.to/brayan_wafula_2c36816f4c3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brayan_wafula_2c36816f4c3"/>
    <language>en</language>
    <item>
      <title>Mastering SQL: Window Functions, Joins, Common Table Expressions (CTEs), and Subqueries Using a Hospital Database</title>
      <dc:creator>Brayan Wafula</dc:creator>
      <pubDate>Tue, 20 Oct 2026 23:44:13 +0000</pubDate>
      <link>https://dev.to/brayan_wafula_2c36816f4c3/mastering-sql-window-functions-joins-common-table-expressions-ctes-and-subqueries-using-a-1ccf</link>
      <guid>https://dev.to/brayan_wafula_2c36816f4c3/mastering-sql-window-functions-joins-common-table-expressions-ctes-and-subqueries-using-a-1ccf</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Structured Query Language (SQL) is a standard programming language used to store, retrieve, manipulate, and analyze data in relational databases. &lt;br&gt;
  In a hospital environment, SQL helps manage patient records, appointments, doctors, departments, medical bills, and payments. But, as hospital databases grow, basic queries using &lt;code&gt;SELECT&lt;/code&gt;, &lt;code&gt;WHERE&lt;/code&gt;, and &lt;code&gt;ORDER BY&lt;/code&gt; may not be sufficient for complex analytical tasks.&lt;br&gt;
Some example are, a hospital administrator may need to&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Rank doctors by revenue.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Identify patients with outstanding balances.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Determine which departments have the highest number of appointments.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Compare monthly payments.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SQL provides several advanced techniques for solving these problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Window functions&lt;/strong&gt; perform calculations across related rows without combining them into a single result row.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SQL joins&lt;/strong&gt; combine information from two or more tables using related columns.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Common Table Expressions (CTEs)&lt;/strong&gt; create named query results that simplify complex SQL statements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Subqueries&lt;/strong&gt; allow one SQL query to be embedded inside another query.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This article explains these concepts, their different types, their practical applications, and their differences using a hospital database in PostgreSQL.&lt;/p&gt;
&lt;h2&gt;
  
  
  SQL Window Functions
&lt;/h2&gt;
&lt;h4&gt;
  
  
  What are window functions?
&lt;/h4&gt;

&lt;p&gt;SQL window functions (also known as &lt;em&gt;analytic functions&lt;/em&gt;) perform calculations across a set of table rows that are related to the current row, without collapsing the result set into a single output row. This set of rows is called a &lt;em&gt;window&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Unlike a standard &lt;code&gt;GROUP BY&lt;/code&gt; clause, which compresses your rows to show only the summaries, window functions preserve the original granularity of your data. Every single record remains visible, and the calculated value appears as a new column alongside your existing details&lt;/p&gt;

&lt;p&gt;Window functions are useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ranking doctors by revenue.&lt;/li&gt;
&lt;li&gt;Finding the previous or next patient payment.&lt;/li&gt;
&lt;li&gt;Calculating running totals.&lt;/li&gt;
&lt;li&gt;Comparing current payments with earlier payments.&lt;/li&gt;
&lt;li&gt;Identifying the highest and lowest payments.&lt;/li&gt;
&lt;li&gt;Dividing patients into analytical groups.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The general syntax is:&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="k"&gt;column_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="n"&gt;window_function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; 
&lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;grouping_column&lt;/span&gt; 
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sorting_column&lt;/span&gt; 
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;result&lt;/span&gt; 
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;OVER()&lt;/code&gt; clause defines the window over which the function operates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding OVER(), PARTITION BY, ORDER BY, and window frames
&lt;/h3&gt;

&lt;p&gt;These components determine how a window function processes data.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;A. OVER()&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;OVER()&lt;/code&gt; clause in SQL defines a "window" of rows around the current row to perform a calculation. It turns standard functions (like &lt;code&gt;SUM&lt;/code&gt;, &lt;code&gt;AVG&lt;/code&gt;, or &lt;code&gt;ROW_NUMBER&lt;/code&gt;) into window functions, allowing you to calculate aggregates or rankings without losing your underlying row-level data&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;B. PARTITION BY&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;In SQL, the &lt;code&gt;PARTITION BY&lt;/code&gt; clause is a sub-clause used inside window functions (via the &lt;code&gt;OVER()&lt;/code&gt; clause) to divide a query's result set into smaller, isolated groups—called &lt;em&gt;partitions&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The defining characteristic of &lt;code&gt;PARTITION BY&lt;/code&gt; is that it performs group-level calculations while keeping every individual row intact. Calculations (like sums, averages, or rankings) are calculated independently within each partition and reset when moving to the next group.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;C. ORDER BY&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The SQL &lt;code&gt;ORDER BY&lt;/code&gt; clause is used to sort the result set of a query in either ascending or descending order. Without it, a database does not guarantee the order of the returned rows, meaning they can appear random or change between query runs&lt;/p&gt;

&lt;h5&gt;
  
  
  1. &lt;em&gt;Basic Syntax&lt;/em&gt;
&lt;/h5&gt;

&lt;p&gt;The &lt;code&gt;ORDER BY&lt;/code&gt; clause always goes at the very end of your SQL query (or right before a &lt;code&gt;LIMIT&lt;/code&gt; / &lt;code&gt;TOP&lt;/code&gt; clause if you are restricting rows).&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="n"&gt;column1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;column2&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;column_name&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;ASC&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;• &lt;code&gt;ASC&lt;/code&gt; (Ascending): Sorts data from smallest to largest (A to Z, 0 to 9, oldest date to newest). This is the default setting, so you do not have to explicitly type it.&lt;br&gt;
• &lt;code&gt;DESC&lt;/code&gt;(Descending): Sorts data from largest to smallest (Z to A, 9 to 0, newest date to oldest).&lt;/p&gt;
&lt;h5&gt;
  
  
  2. &lt;em&gt;Order of Execution&lt;/em&gt;
&lt;/h5&gt;

&lt;p&gt;It helps to know that SQL doesn't read your query from top to bottom. The database processes ORDER BY near the very end of its execution cycle:&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;SQL&lt;/span&gt; &lt;span class="n"&gt;EXECUTION&lt;/span&gt; &lt;span class="k"&gt;ORDER&lt;/span&gt;
 &lt;span class="cm"&gt;/* 
 * 1.FROM
 * 2.WHERE
 * 3.GROUP BY
 * 4.HAVING
 * 5.SELECT
 * 6.ORDER BY
 * 7.LIMIT
 */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Because it runs after the &lt;code&gt;SELECT&lt;/code&gt;statement, you can actually sort your data using &lt;strong&gt;column aliases&lt;/strong&gt; that you created inside your &lt;code&gt;SELECT&lt;/code&gt;clause.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;D. Window frames&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;A window frame in SQL is a sub-selection of rows within a partition that determines exactly which records are included in a window function's calculation for the current row.&lt;/p&gt;

&lt;p&gt;While &lt;code&gt;PARTITION BY&lt;/code&gt; groups the data and &lt;code&gt;ORDER BY&lt;/code&gt; sorts it, the window frame clause defines a sliding or fixed boundary around the current row. As SQL evaluates the query row-by-row, this "frame" shifts to look backward, forward, or at a fixed range of data.&lt;/p&gt;

&lt;h5&gt;
  
  
  1. &lt;em&gt;The Anatomy of a Window Frame&lt;/em&gt;
&lt;/h5&gt;

&lt;p&gt;A window frame is written at the very end of the OVER() clause using this basic syntax:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;window_function&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;column1&lt;/span&gt;
    &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;column2&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;ROWS&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="k"&gt;RANGE&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;GROUPS&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;start_boundary&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;end_boundary&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The Boundaries&lt;/p&gt;

&lt;p&gt;To set the frame, you mix and match these five boundary markers:&lt;br&gt;
• &lt;code&gt;UNBOUNDED PRECEDING&lt;/code&gt;: The very first row of the partition.&lt;br&gt;
• &lt;code&gt;N PRECEDING&lt;/code&gt;: N rows before the current row.&lt;br&gt;
• &lt;code&gt;CURRENT ROW&lt;/code&gt;: The row currently being processed.&lt;br&gt;
• &lt;code&gt;N FOLLOWING&lt;/code&gt;: N rows after the current row.&lt;br&gt;
• &lt;code&gt;UNBOUNDED FOLLOWING&lt;/code&gt;: The very last row of the partition.&lt;/p&gt;

&lt;p&gt;The main frame options are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ROWS&lt;/code&gt;: selects rows according to their physical positions.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RANGE&lt;/code&gt;: selects rows based on ordering values and their peers.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;GROUPS&lt;/code&gt;: selects groups of rows with equal ordering values.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;ROWS vs. RANGE vs. GROUPS&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;How SQL counts its boundaries depends on the modifier you choose&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Modifier&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Based On&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Best Used For&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;ROWS&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Physical row position. It counts individual rows regardless of whether they contain identical values.&lt;/td&gt;
&lt;td&gt;Moving averages, such as calculating the average of the last three physical transactions.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;RANGE&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Logical values in the &lt;code&gt;ORDER BY&lt;/code&gt; column. Rows with identical ordering values are treated as peers.&lt;/td&gt;
&lt;td&gt;Time-series analysis, such as calculating values within a specified range of dates, regardless of the number of transactions.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;GROUPS&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Groups of rows with identical ordering values. Each unique group is treated as a single step.&lt;/td&gt;
&lt;td&gt;Analyzing grouped data, particularly when handling tied values or transactions with identical ordering values.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Types of SQL window functions
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;A. Ranking Window Functions&lt;/strong&gt;&lt;br&gt;
These functions assign a sequential integer or statistical rank to each row within a designated partition based on a specific order.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ROW_NUMBER()&lt;/code&gt; - Assigns a unique, sequential integer to rows starting at 1. Never duplicates numbers if values match&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;RANK()&lt;/code&gt; - : Assigns ranks based on values. If duplicate values exist, they receive the same rank, and gaps are skipped for the next rank numbers (e.g., 1, 2, 2, 4).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;DENSE_RANK()&lt;/code&gt; - Similar to &lt;code&gt;RANK()&lt;/code&gt;, but it does not skip any numbers when there are duplicates &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;NTILE(N)&lt;/code&gt; - Divides an ordered partition into &lt;code&gt;N&lt;/code&gt; roughly equal buckets or groups and assigns the bucket number to each row.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;PERCENT_RANK()&lt;/code&gt; - Computes the relative rank of a row as a percentage value between 0 and 1.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;B. Value / Offset Window Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Value (or offset) functions allow you to access data from a different row relative to the current row without using complex self-joins.&lt;br&gt;
• &lt;code&gt;LAG()&lt;/code&gt;: Accesses data from a previous row in the same result set, useful for calculating period-over-period growth.&lt;/p&gt;

&lt;p&gt;• &lt;code&gt;LEAD()&lt;/code&gt;: Accesses data from a subsequent row in the same result set.&lt;/p&gt;

&lt;p&gt;• &lt;code&gt;FIRST_VALUE()&lt;/code&gt;: Returns the first value in an ordered window frame.&lt;/p&gt;

&lt;p&gt;• &lt;code&gt;LAST_VALUE()&lt;/code&gt;: Returns the last value in an ordered window frame (note: usually requires altering the default window frame to look past the current row).&lt;/p&gt;

&lt;p&gt;• &lt;code&gt;NTH_VALUE()&lt;/code&gt;: Retrieves the value from the specific (N^{th}) row of the window frame.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C. Aggregate Window Functions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These are standard SQL aggregate functions applied using the &lt;code&gt;OVER()&lt;/code&gt; clause. Instead of reducing the rows, they return a cumulative or moving calculation for each row.&lt;/p&gt;

&lt;p&gt;• &lt;code&gt;SUM()&lt;/code&gt;: Computes a cumulative running total when paired with an ORDER BY clause.&lt;/p&gt;

&lt;p&gt;• &lt;code&gt;AVG()&lt;/code&gt;: Calculates moving or partitioned averages.&lt;/p&gt;

&lt;p&gt;• &lt;code&gt;COUNT()&lt;/code&gt;: Calculates running or partitioned counts of rows.&lt;/p&gt;

&lt;p&gt;• &lt;code&gt;MIN()&lt;/code&gt; / &lt;code&gt;MAX()&lt;/code&gt;: Identifies the lowest or highest value up to the current row or within the partition.&lt;/p&gt;
&lt;h2&gt;
  
  
  SQL Joins
&lt;/h2&gt;
&lt;h3&gt;
  
  
  What are SQL joins?
&lt;/h3&gt;

&lt;p&gt;An &lt;em&gt;&lt;strong&gt;SQL JOIN&lt;/strong&gt;&lt;/em&gt; clause is used to combine rows from two or more tables based on a related column between them. It is fundamental to relational databases, allowing you to reassemble data that has been split up to avoid duplication.&lt;/p&gt;

&lt;p&gt;A. &lt;strong&gt;INNER JOIN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The most common join type. It filters out any rows that do not strictly find a match in the opposing table. An &lt;code&gt;INNER JOIN&lt;/code&gt; is useful when a report must include only records with valid matches in both tables.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Standard Syntax&lt;/em&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column_name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;
&lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common_column&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common_column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;• &lt;code&gt;INNER JOIN&lt;/code&gt;: Specifies the second table you want to merge.&lt;br&gt;
• &lt;code&gt;ON&lt;/code&gt;: Defines the condition or rule for matching rows, typically mapping a Primary Key from one table to a Foreign Key in another.&lt;/p&gt;

&lt;p&gt;B. &lt;strong&gt;LEFT JOIN (or LEFT OUTER JOIN)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In SQL, a LEFT JOIN (or LEFT OUTER JOIN) returns all rows from the left table and the matching rows from the right table. If no match is found for a row in the right table, the database outputs NULL values for the right table's columns.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Standard Syntax&lt;/em&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table_left&lt;/span&gt;
&lt;span class="k"&gt;LEFT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;table_right&lt;/span&gt; 
  &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;table_left&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common_column&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table_right&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common_column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;When no match exists, columns from the right table contain &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;C. &lt;strong&gt;RIGHT JOIN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In SQL, a RIGHT JOIN (or RIGHT OUTER JOIN) is used to combine rows from two tables, returning all records from the right table and the matched records from the left table. If there is no match for a row from the right table, the result will contain NULL values for the columns of the left table.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Standard Syntax&lt;/em&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table_left&lt;/span&gt;
&lt;span class="k"&gt;RIGHT&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;table_right&lt;/span&gt; 
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;table_left&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common_column&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table_right&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common_column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;D. &lt;strong&gt;FULL OUTER JOIN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In SQL, a &lt;code&gt;FULL OUTER JOIN&lt;/code&gt; (or simply &lt;code&gt;FULL JOIN&lt;/code&gt;) returns all records from both tables, regardless of whether they have a matching row in the other table.&lt;/p&gt;

&lt;p&gt;It essentially combines the functionality of a &lt;code&gt;LEFT JOIN&lt;/code&gt; and a &lt;code&gt;RIGHT JOIN&lt;/code&gt;. When a match is found based on the join condition, the rows are merged. If there is no match, the missing side is filled with &lt;code&gt;NULL&lt;/code&gt;values&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Basic Syntax&lt;/em&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;column1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;column2&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;
&lt;span class="k"&gt;FULL&lt;/span&gt; &lt;span class="k"&gt;OUTER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt; 
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common_column&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common_column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;E. &lt;strong&gt;CROSS JOIN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An SQL &lt;code&gt;CROSS JOIN&lt;/code&gt; combines every row from the first table with every row from the second table. It creates a &lt;strong&gt;Cartesian product&lt;/strong&gt; of the two tables, meaning it generates all possible combinations of your data.&lt;br&gt;
  Unlike other joins (like &lt;code&gt;INNER JOIN&lt;/code&gt; or &lt;code&gt;LEFT JOIN&lt;/code&gt;), a &lt;code&gt;CROSS JOIN&lt;/code&gt; does not require a join condition (no &lt;code&gt;ON&lt;/code&gt; clause) because it is explicitly pairing everything together&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Basic Syntax&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can write a cross join explicitly using the CROSS JOIN keyword, or implicitly using a comma.&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="n"&gt;columns&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table1&lt;/span&gt;
&lt;span class="k"&gt;CROSS&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;table2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;F. &lt;strong&gt;SELF JOIN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An SQL Self Join is a regular join where a table is joined with itself. There is no specific &lt;code&gt;SELF JOIN&lt;/code&gt; keyword; instead, you reference the same table twice and use &lt;strong&gt;table aliases&lt;/strong&gt; to give them distinct names. This tricks SQL into treating them as two separate tables so you can compare rows within the same dataset.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Basic Syntax&lt;/em&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;SELECT&lt;/span&gt; 
    &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;column_name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; 
    &lt;span class="n"&gt;your_table&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;
&lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; 
    &lt;span class="n"&gt;your_table&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; 
&lt;span class="k"&gt;ON&lt;/span&gt; 
    &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common_column&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;related_column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;A self-join is useful for hierarchical data, referral relationships, and comparing records within the same table.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The appropriate join depends on which records must remain in the output and whether unmatched records are important to the analysis.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Table Expressions (CTEs)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is a CTE?
&lt;/h3&gt;

&lt;p&gt;A Common Table Expression (CTE) is a temporary, named result set in SQL that you can reference within a single &lt;code&gt;SELECT&lt;/code&gt;, &lt;code&gt;INSERT&lt;/code&gt;, &lt;code&gt;UPDATE&lt;/code&gt;, or &lt;code&gt;DELETE&lt;/code&gt;statement. Defined using the &lt;code&gt;WITH&lt;/code&gt; &lt;strong&gt;keyword&lt;/strong&gt;, CTEs act like virtual, query-scoped tables that disappear as soon as the query finishes executing. They are widely preferred over traditional subqueries because they heavily improve query readability, modularity, and code organization.&lt;/p&gt;

&lt;p&gt;CTEs make complex queries easier to read by breaking them into logical steps.&lt;/p&gt;

&lt;p&gt;The basic syntax is:&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;WITH&lt;/span&gt; &lt;span class="n"&gt;cte_name&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="p"&gt;...&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;cte_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A CTE is not automatically a permanent table. It does not create a persistent database object.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Multiple CTE&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Multiple CTEs allow a query to be divided into several named stages. Multiple CTEs are useful when each calculation depends on a previous step. They make a long query easier to maintain and troubleshoot.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SYNTAX STRUCTURE&lt;/em&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;WITH&lt;/span&gt; &lt;span class="n"&gt;first_cte&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;department_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;avg_sal&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;department_id&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="c1"&gt;-- &amp;lt;-- Separated by a comma&lt;/span&gt;

&lt;span class="n"&gt;second_cte&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;department_id&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;first_cte&lt;/span&gt; &lt;span class="c1"&gt;-- &amp;lt;-- Can reference the preceding CTE!&lt;/span&gt;
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;avg_sal&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;75000&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;-- &amp;lt;-- No comma before the main query&lt;/span&gt;

&lt;span class="c1"&gt;-- The final main statement (SELECT, INSERT, UPDATE, or DELETE)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;employee_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&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;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;department_id&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;second_cte&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;department_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;department_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The Rules of Multiple CTEs&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Single WITH Clause&lt;/strong&gt;: You only write WITH before the first CTE. Do not repeat it for subsequent ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Comma-Separated&lt;/strong&gt;: Place a comma between the closing parenthesis of one CTE and the name of the next.
3.** No Trailing Comma**: Do not put a comma between your final CTE definition and the main query.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Order Matters (No Forward References)&lt;/strong&gt;: A CTE can reference any CTE defined before it, but it cannot reference a CTE defined after it.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Recursive CTEs
&lt;/h4&gt;

&lt;p&gt;A recursive CTE references its own result to process hierarchical or sequential data.&lt;/p&gt;

&lt;p&gt;It typically contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An anchor query that identifies the starting rows.&lt;/li&gt;
&lt;li&gt;A recursive query that finds the next related rows.&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;UNION ALL&lt;/code&gt;combining the anchor and recursive results.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Structural Anatomy of a Recursive CTE&lt;/p&gt;

&lt;p&gt;A recursive CTE always consists of three fundamental components combined using the UNION ALL operator:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Anchor Member (Base Query)&lt;/strong&gt;: The initial query that returns the starting rows of the recursion (e.g., the top-level boss or the number 1).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Recursive Member&lt;/strong&gt;: The query that references the CTE itself. It joins the table back to the previous iteration's results to find the next level of data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Termination Condition&lt;/strong&gt;: A condition (usually a &lt;code&gt;WHERE&lt;/code&gt;clause) in the recursive member that stops the query from executing infinitely.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Basic Syntax&lt;/em&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;WITH&lt;/span&gt; &lt;span class="k"&gt;RECURSIVE&lt;/span&gt; &lt;span class="n"&gt;cte_name&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;-- 1. Anchor Member&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt; 

    &lt;span class="k"&gt;UNION&lt;/span&gt; &lt;span class="k"&gt;ALL&lt;/span&gt;

    &lt;span class="c1"&gt;-- 2. Recursive Member + 3. Termination Condition&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;columns&lt;/span&gt; 
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;
    &lt;span class="k"&gt;INNER&lt;/span&gt; &lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;cte_name&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parent_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;termination_condition&lt;/span&gt;&lt;span class="p"&gt;]&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;cte_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;The main advantage of a CTE is often clarity rather than guaranteed performance improvement.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  SQL Subqueries
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is a subquery?
&lt;/h3&gt;

&lt;p&gt;An SQL subquery is a &lt;code&gt;SELECT&lt;/code&gt;statement nested inside another SQL statement and enclosed in parentheses (). The outer statement (often called the main query) consumes the results generated by the inner subquery to perform filtering, calculations, or data transformations.&lt;/p&gt;

&lt;p&gt;Subqueries can be nested inside &lt;code&gt;SELECT&lt;/code&gt;, &lt;code&gt;INSERT&lt;/code&gt;, &lt;code&gt;UPDATE&lt;/code&gt;, or &lt;code&gt;DELETE&lt;/code&gt; statements, and they can reside within clauses like &lt;code&gt;WHERE&lt;/code&gt;, &lt;code&gt;FROM&lt;/code&gt;, &lt;code&gt;SELECT&lt;/code&gt;, and &lt;code&gt;HAVING&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Subqueries by Result Shape&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The SQL optimizer categorizes subqueries based on the structural format of the data they return:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalar Subquery&lt;/strong&gt;: Returns exactly one row and one column (a single value). It can step in anywhere a standard literal value or column expression is used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-Row (Column)&lt;/strong&gt; Subquery: Returns a single column containing multiple rows of values. This type requires set membership operators like IN, ANY, or ALL in the outer query.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Table Subquery (Derived Table)&lt;/strong&gt;: Returns multiple columns and multiple rows. It acts as a temporary in-memory table and is primarily utilized within the FROM clause.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Non-correlated subqueries&lt;/strong&gt;:A non-correlated subquery does not refer to columns from the outer query. It can be evaluated independently of the outer query's individual rows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Correlated subqueries&lt;/strong&gt;:A correlated subquery references a column from the outer query. Its result depends on the current outer row. A correlated subquery is useful when a condition must be evaluated relative to each outer record. Depending on the query and indexes, PostgreSQL may optimize it into an efficient execution plan; correlation does not automatically mean the query will be slow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Nested subqueries&lt;/strong&gt;:A nested subquery contains another subquery inside it. Nested subqueries are useful for multi-level comparisons, although a CTE may make the same logic easier to read.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Subqueries using IN&lt;/strong&gt;: In SQL, a subquery using the IN operator allows you to filter the results of an outer query based on a dynamic list of values returned by an inner query. It acts as a powerful, flexible alternative to writing multiple OR conditions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Basic syntax&lt;/strong&gt;&lt;/em&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;SELECT&lt;/span&gt; &lt;span class="k"&gt;column_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table_1&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;column_to_check&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;matching_column&lt;/span&gt; 
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table_2&lt;/span&gt; 
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subqueries using EXISTS&lt;/strong&gt;: In SQL, the &lt;code&gt;EXISTS&lt;/code&gt; operator is a boolean condition used within a &lt;code&gt;WHERE&lt;/code&gt; clause to check whether a subquery returns any rows at all. It evaluates to TRUE if the subquery returns at least one row, and FALSE if it returns no rows.
Because &lt;code&gt;EXISTS&lt;/code&gt;only looks for the presence of a matching row, the database stops processing the subquery the exact moment it finds its first match. This makes it highly efficient, particularly when filtering large datasets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Basic Syntax&lt;/strong&gt;&lt;/em&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;column_names&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table_1&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; 
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;table_2&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subqueries using ANY&lt;/strong&gt;: The SQL ANY operator is used in a &lt;code&gt;WHERE&lt;/code&gt; or &lt;code&gt;HAVING&lt;/code&gt; clause to compare a single value against a set of values returned by a multi-row subquery. The condition evaluates to TRUE if the comparison holds true for at least one value in the subquery's result set.
In most SQL dialects (like MySQL, PostgreSQL, SQL Server, and Oracle), SOME is a direct alias for &lt;code&gt;ANY&lt;/code&gt;, meaning they function exactly the same way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Basic Syntax&lt;/strong&gt;&lt;/em&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;column_names&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;column_name&lt;/span&gt; &lt;span class="n"&gt;comparison_operator&lt;/span&gt; &lt;span class="k"&gt;ANY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subquery&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The comparison operator must be a standard operator: &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &amp;gt;=, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt;, or &lt;code&gt;!=&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subqueries using ALL&lt;/strong&gt;: In SQL, the &lt;code&gt;ALL&lt;/code&gt; operator is used to compare a single scalar value against every single value returned by a multi-row subquery.
A condition using &lt;code&gt;ALL&lt;/code&gt; evaluates to &lt;code&gt;TRUE&lt;/code&gt; only if the comparison holds &lt;code&gt;true&lt;/code&gt; for all records in the subquery result set. It must always be preceded by a standard comparison operator (like &lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;&lt;/code&gt;, &lt;code&gt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Syntax&lt;/strong&gt;&lt;/em&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;column_names&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="k"&gt;column_name&lt;/span&gt; &lt;span class="n"&gt;comparison_operator&lt;/span&gt; &lt;span class="k"&gt;ALL&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subquery&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;-&lt;strong&gt;Subqueries in the SELECT clause&lt;/strong&gt;:A subquery in the &lt;code&gt;SELECT&lt;/code&gt; clause (also known as a &lt;strong&gt;scalar subquery or a projection subquery&lt;/strong&gt;) allows you to generate a dynamic, calculated column for every row returned by the outer query.&lt;br&gt;
Instead of just pulling a standard column from a table, you insert an entirely separate &lt;code&gt;SELECT&lt;/code&gt; statement directly into your main column list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Golden Rule&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A subquery placed in the &lt;code&gt;SELECT&lt;/code&gt; clause must return exactly one value (one row and one column) per outer row. If it returns multiple columns or multiple rows, the database engine will throw a syntax runtime error. If it returns no rows, it evaluates to &lt;code&gt;NULL&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;-&lt;strong&gt;Subqueries in the FROM clause&lt;/strong&gt;:In SQL, a subquery in the FROM clause acts as a temporary, virtual table that the main query can use to select, filter, or join data. This is often called a &lt;strong&gt;derived table or an inline view&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Two Golden Rules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When placing a nested SELECT statement inside your FROM clause, you must follow these two syntax rules:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Enclose it in parentheses&lt;/strong&gt;: The entire subquery must live inside (...).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assign an Alias&lt;/strong&gt;: You must give the subquery a name (an alias) using the AS keyword (though AS is optional in some SQL dialects, the alias name itself is mandatory).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Syntax Structure&lt;/strong&gt;&lt;/em&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;SELECT&lt;/span&gt; 
    &lt;span class="n"&gt;derived_table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;column1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="n"&gt;derived_table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;column2&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;-- The Inner Subquery&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;column1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;column2&lt;/span&gt; 
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;original_table&lt;/span&gt;
    &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;derived_table&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;-- Mandatory Alias&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Subqueries in the WHERE clause&lt;/strong&gt;: A subquery in a &lt;code&gt;WHERE&lt;/code&gt; clause (also known as a &lt;strong&gt;nested query or inner query&lt;/strong&gt;) is a SELECT statement embedded inside the filtering condition of an outer SQL query. It acts as a dynamic filter, calculating a temporary value or dataset that the outer query uses to evaluate rows.
Depending on how many rows and columns the inner query returns, you must couple it with the appropriate SQL operator.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Best Practices When Using Advanced SQL
&lt;/h2&gt;

&lt;p&gt;The following practices improve query accuracy, performance, and maintainability.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Understand the relationships between tables. Identify primary keys, foreign keys, and the correct join columns before writing a complex query.&lt;/li&gt;
&lt;li&gt;Prevent duplicate counting. One-to-many joins can multiply rows. Aggregate at the appropriate level before joining when necessary.&lt;/li&gt;
&lt;li&gt;Use meaningful aliases. Aliases such as &lt;code&gt;p&lt;/code&gt;, &lt;code&gt;pay&lt;/code&gt;, and &lt;code&gt;doc&lt;/code&gt; make queries easier to read when used consistently.&lt;/li&gt;
&lt;li&gt;Choose the correct window ordering. If multiple rows have the same date or value, include a unique secondary sort column when deterministic results are required.&lt;/li&gt;
&lt;li&gt;Specify window frames explicitly when necessary. This is especially important for running totals and functions such as &lt;code&gt;LAST_VALUE()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Handle NULL values. Remember that &lt;code&gt;SUM()&lt;/code&gt; over no input rows can return NULL, and &lt;code&gt;COUNT(column)&lt;/code&gt; ignores NULL values. Use &lt;code&gt;COALESCE()&lt;/code&gt; when a zero is appropriate.&lt;/li&gt;
&lt;li&gt;Choose joins based on reporting requirements. An inner join excludes unmatched records, while an outer join preserves them.&lt;/li&gt;
&lt;li&gt;Use CTEs to improve readability. Break complex queries into understandable stages instead of building one unnecessarily complicated statement.&lt;/li&gt;
&lt;li&gt;Check query performance. Use PostgreSQL's &lt;code&gt;EXPLAIN&lt;/code&gt; and, where appropriate, &lt;code&gt;EXPLAIN ANALYZE&lt;/code&gt; to understand execution plans and identify bottlenecks.&lt;/li&gt;
&lt;li&gt;Protect patient information. Hospital databases contain confidential information. Access should be authorized, and reports should expose only the data necessary for their purpose.&lt;/li&gt;
&lt;li&gt;Validate results against the source data. Compare totals, row counts, and sample records to ensure that a query has not excluded or duplicated information.&lt;/li&gt;
&lt;li&gt;Use appropriate indexes. Indexes on frequently joined keys and filtered columns can improve performance, although their value depends on the query and the data.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Window functions, joins, Common Table Expressions, and subqueries are important SQL techniques for solving complex data problems.&lt;/p&gt;

&lt;p&gt;Window functions allow analysts to rank records, compare payments over time, and calculate totals while preserving individual rows. Joins combine related information from different tables, enabling meaningful hospital reports. CTEs organize complex calculations into readable stages and support recursive analysis of hierarchical data. Subqueries provide a flexible way to filter, compare, and calculate values based on other query results.&lt;br&gt;
In a hospital environment, these techniques can support patient payment analysis, appointment monitoring, doctor performance reporting, departmental planning, and financial reconciliation.&lt;/p&gt;

&lt;p&gt;The most important skill is not memorizing SQL syntax. It is understanding the business question, identifying the correct relationships between tables, selecting the appropriate SQL technique, and verifying that the results accurately represent the underlying data.&lt;/p&gt;

&lt;p&gt;By practising these techniques in PostgreSQL and applying them to a hospital dataset, SQL learners can develop the analytical skills needed to transform raw records into reliable and useful information for decision-making.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“The goal is to turn data into information, and information into insight.”&lt;br&gt;
— Carly Fiorina, former CEO of Hewlett-Packard&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>sql</category>
      <category>cte</category>
      <category>dbms</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Power BI Technical Article: Data Modelling, Relationships &amp; Joins</title>
      <dc:creator>Brayan Wafula</dc:creator>
      <pubDate>Mon, 19 Oct 2026 06:27:43 +0000</pubDate>
      <link>https://dev.to/brayan_wafula_2c36816f4c3/power-bi-technical-article-data-modelling-relationships-joins-2jo7</link>
      <guid>https://dev.to/brayan_wafula_2c36816f4c3/power-bi-technical-article-data-modelling-relationships-joins-2jo7</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“The goal is to turn data into information, and information into insight.” — Carly Fiorina.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Power BI is much more than a visualization tool—it is a complete Business Intelligence (BI) platform that allows organizations to transform raw data into meaningful insights. However, the quality of reports depends heavily on how the underlying data is structured. A poorly designed model leads to slow reports, confusing DAX formulas, duplicated data, and difficult maintenance. A well-designed model, on the other hand, produces fast, scalable, and reliable analytics.&lt;/p&gt;

&lt;p&gt;This article explains the principles of data modelling, fact and dimension tables, relationships, filter propagation, joins in Power Query, and concludes with the recommended design for real-world BI projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Modelling in Power BI
&lt;/h2&gt;

&lt;h4&gt;
  
  
  What is data modelling?
&lt;/h4&gt;

&lt;p&gt;Data modeling in Power BI is the process of structuring, shaping, and connecting your data tables in the Model Data with Power BI tool to build a reliable semantic model for fast and accurate reporting. Instead of keeping everything in one spreadsheet, data is divided into logical tables that represent business entities such as customers, products, dates, and sales.&lt;/p&gt;

&lt;p&gt;A strong data model improves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Performance by reducing unnecessary data duplication.&lt;/li&gt;
&lt;li&gt;DAX calculations because measures become simpler.&lt;/li&gt;
&lt;li&gt;Scalability when new data is added.&lt;/li&gt;
&lt;li&gt;Maintainability since tables have clear responsibilities.&lt;/li&gt;
&lt;li&gt;Report accuracy through consistent filtering.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  A. Flat Table Schema
&lt;/h4&gt;

&lt;p&gt;A flat table schema (also known as "One Big Table" or an un-pivoted/denormalized dataset) is a data modeling structure where all transactional data, attributes, and descriptive fields are consolidated into a single, wide table.A flat table stores every piece of information inside one large table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Everything—customer names, products, locations, dates, and sales values—exists in one table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easy for beginners.&lt;/li&gt;
&lt;li&gt;Simple to import from Excel.&lt;/li&gt;
&lt;li&gt;No relationship configuration required.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large file size.&lt;/li&gt;
&lt;li&gt;Repeated customer and product information.&lt;/li&gt;
&lt;li&gt;Slower performance.&lt;/li&gt;
&lt;li&gt;Difficult to maintain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Best used when: Small datasets with limited reporting needs.&lt;/p&gt;

&lt;h4&gt;
  
  
  B. Star Schema
&lt;/h4&gt;

&lt;p&gt;A Star Schema is a data modeling approach where a central fact table connects directly to multiple surrounding dimension tables&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One central fact table.&lt;/li&gt;
&lt;li&gt;Multiple surrounding dimensions.&lt;/li&gt;
&lt;li&gt;Relationships are usually one-to-many.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fens7w35qbvg3k14g43p8.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fens7w35qbvg3k14g43p8.webp" alt="star schema" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Excellent performance.&lt;/li&gt;
&lt;li&gt;Simple DAX.&lt;/li&gt;
&lt;li&gt;Easy filtering.&lt;/li&gt;
&lt;li&gt;Highly scalable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requires planning.&lt;/li&gt;
&lt;li&gt;Slightly more complex than a flat table.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Best used when: Sales, finance, inventory, healthcare, education, and enterprise BI.&lt;/p&gt;

&lt;h4&gt;
  
  
  C. Snowflake Schema
&lt;/h4&gt;

&lt;p&gt;a data-modeling structure where dimension tables are normalized and split into multiple related sub-tables&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of storing category inside DimProduct, it is moved into DimCategory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbegipjtz07wk5nz1l3v5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbegipjtz07wk5nz1l3v5.png" alt="snowflake schema" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduces redundancy.&lt;/li&gt;
&lt;li&gt;Better normalized database design.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More tables.&lt;/li&gt;
&lt;li&gt;More complex relationships.&lt;/li&gt;
&lt;li&gt;Harder DAX and navigation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Best used when: Very large enterprise warehouse environments. &lt;/p&gt;

&lt;h2&gt;
  
  
  2. Fact Tables and Dimension Tables
&lt;/h2&gt;

&lt;p&gt;Understanding the operational dichotomy between Fact and Dimension tables is critical to structuring an efficient Star Schema&lt;/p&gt;

&lt;h3&gt;
  
  
  Fact Tables
&lt;/h3&gt;

&lt;p&gt;Fact tables store the quantitative metrics generated by operational business events. They capture the observations, measurements, or numerical transactions of a business process.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Contents: Numeric values (Revenue, Quantity, Cost), timestamps, and alphanumeric Foreign Keys.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Grain/Granularity:This defines what an individual row in the table represents. For example, a row in FactSales might represent an individual item scan on a point-of-sale receipt (High Granularity), or it could represent aggregated daily sales per store (Low Granularity). Enforcing a consistent grain across a fact table is vital for valid data aggregation.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Examples: FactSales, FactOrder, FactTransactions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Dimension Tables
&lt;/h3&gt;

&lt;p&gt;Dimension tables store the descriptive attributes that provide context to your business metrics. They answer the "who, what, where, when, and why" questions of an analytical query.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Contents: Text-heavy rows containing descriptive context, hierarchies, and categorizations used for slicing, dicing, grouping, and filtering reports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Examples: DimCustomer (Name, Segment, Email), DimProduct (Color, Brand, Category), DimDate (Year, Quarter, Month), DimLocation (City, State, Zip).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Relationships in Power BI
&lt;/h2&gt;

&lt;p&gt;Relationships in Power BI are logical links between tables based on a shared key or column. They allow Power BI to combine data, calculate metrics, and propagate filters across multiple tables without needing to physically merge them. &lt;br&gt;
A relationship tells Power BI how tables are connected. Without relationships, visuals from different tables cannot interact correctly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Relationships
&lt;/h3&gt;

&lt;p&gt;• &lt;strong&gt;One-to-Many (1:&lt;em&gt;) / Many-to-One (&lt;/em&gt;:1)&lt;/strong&gt;: The standard and recommended configuration. One table contains unique values (e.g., a Date or Customer dimension table), while the related table contains multiple matching records (e.g., a Sales or Orders fact table).&lt;/p&gt;

&lt;p&gt;•** One-to-One (1:1)**: Both tables contain unique values for the key. Best practice is usually to merge these tables in Power Query instead.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Many-to-Many (*:)&lt;/strong&gt;: Both tables contain multiple records for the same key. This often causes ambiguous filtering, duplicated totals, and performance issues unless managed with a bridge table.&lt;/p&gt;

&lt;h3&gt;
  
  
  Primary Key and Foreign Key
&lt;/h3&gt;

&lt;p&gt;Primary Key is a column in a table where every single row has a unique value with no duplicates or NULL values while a foreign key is a column in a table that contains repeated values pointing back to a primary key in another table.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Primary Key&lt;/th&gt;
&lt;th&gt;Foreign Key&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Unique values&lt;/td&gt;
&lt;td&gt;Repeated values&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Located in dimension&lt;/td&gt;
&lt;td&gt;Located in fact&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Identifies one record&lt;/td&gt;
&lt;td&gt;Links to dimension&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;the table above shows a comparison of primary and foreign keys&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Active vs Inactive Relationships
&lt;/h4&gt;

&lt;p&gt;A table may have multiple possible relationships but Only one relationship can be active. The inactive relationship can be activated inside DAX using &lt;code&gt;USERELATIONSHIP()&lt;/code&gt; when needed.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Filter Direction
&lt;/h2&gt;

&lt;p&gt;Relationships also determine how filters move through the model.Cross-filter direction in Power BI determines the pathway that filter contexts take when moving between related tables in a data model.&lt;/p&gt;

&lt;p&gt;Types of Filter Directions&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Single Direction (Default)&lt;/strong&gt;: Filters flow in one direction only—from the "one" side (lookup/dimension table) to the "many" side (fact table). For example, selecting a product in a Product table filters the Sales table, but filtering the Sales table has no effect on the Product table.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Both / Bi-Directional&lt;/strong&gt;: Filters flow in both directions between the two tables. A filter applied to either table affects the other, allowing data in fact tables to filter related dimension tables.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Joins in Power Query
&lt;/h2&gt;

&lt;p&gt;A join combines tables during data preparation using Merge Queries.&lt;/p&gt;

&lt;p&gt;Joins in Power Query (Power BI) are performed via the Merge Queries feature, which combines two tables into a single table based on one or more common key columns.&lt;/p&gt;

&lt;h4&gt;
  
  
  Types of Joins in Power Query
&lt;/h4&gt;

&lt;p&gt;Power Query supports six join types when merging tables:&lt;/p&gt;

&lt;p&gt;•_ Left Outer (Default)_: All rows from the left table and matching from the right; unmatched right rows show as null.&lt;/p&gt;

&lt;p&gt;•_ Right Outer_: All rows from the right table and matching from the left; unmatched left rows show as null.&lt;/p&gt;

&lt;p&gt;• &lt;em&gt;Full Outer&lt;/em&gt;: All rows from both tables, filling in null for missing matches.&lt;/p&gt;

&lt;p&gt;• &lt;em&gt;Inner&lt;/em&gt;: Only rows with matching values in both tables.&lt;/p&gt;

&lt;p&gt;• &lt;em&gt;Left Anti&lt;/em&gt;: Only rows existing exclusively in the left table.&lt;/p&gt;

&lt;p&gt;• &lt;em&gt;Right Anti&lt;/em&gt;: Only rows existing exclusively in the right table.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;em&gt;How to Do a Join in Power Query&lt;/em&gt;
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;em&gt;Launch the Power Query Editor via Transform Data in Power BI Desktop.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Click Merge Queries (or Merge Queries as New) on the Home ribbon.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Select the primary table and the secondary table from the grids.&lt;/em&gt;
4._ Select the matching key column(s) in both tables._&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Select the desired Join kind and click OK, then use the Expand icon to add columns from the related table.&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  6. Power Query Joins vs Power BI Relationships
&lt;/h2&gt;

&lt;p&gt;Although both connect tables, they serve different purposes.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Merge (Power Query)&lt;/th&gt;
&lt;th&gt;Relationship (Model)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Physically combines data&lt;/td&gt;
&lt;td&gt;Keeps tables separate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Happens during data loading&lt;/td&gt;
&lt;td&gt;Happens after loading&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Creates new columns&lt;/td&gt;
&lt;td&gt;Creates filter paths&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Used in ETL&lt;/td&gt;
&lt;td&gt;Used for analytics&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A relationship allows Power BI to display Customer Name without duplicating data.&lt;br&gt;
This is the preferred BI approach because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Less redundancy&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Smaller model&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Faster refresh&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Better scalability&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Excessive merging creates wide tables similar to flat files, reducing the benefits of dimensional modelling.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Recommended Power BI Model
&lt;/h2&gt;

&lt;p&gt;For most business intelligence projects, I recommend the Star Schema with one-to-many relationships and single-direction filter propagation.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Why the Star Schema is Recommended&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;• &lt;strong&gt;Smaller Size &amp;amp; Compression&lt;/strong&gt;: Separating data into centralized fact tables and surrounding dimension tables reduces storage footprint and improves memory optimization.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Optimized DAX Performance&lt;/strong&gt;: Queries run faster because relationship paths are predictable and filter propagation is clean.&lt;/p&gt;

&lt;p&gt;• &lt;strong&gt;Easier Management&lt;/strong&gt;: Business logic, metrics, and report modifications are much simpler to maintain as your model scales.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;em&gt;Recommended Design&lt;/em&gt;
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Central FactSales table&lt;/li&gt;
&lt;li&gt;Dimensions: DimCustomer, DimProduct, DimDate, DimLocation&lt;/li&gt;
&lt;li&gt;One-to-Many relationships&lt;/li&gt;
&lt;li&gt;Single-direction filtering&lt;/li&gt;
&lt;li&gt;Use Power Query merges only during data cleansing or lookup enrichment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This design balances performance, clarity, flexibility, and long-term maintainability, making it the industry standard for professional Power BI solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Effective Power BI reporting begins with an effective data model. Understanding star schemas, fact and dimension tables, relationships, filter direction, and Power Query joins enables analysts to build models that are accurate, scalable, and easy to maintain. While flat tables may suit small datasets and snowflake schemas benefit highly normalized warehouses, the star schema remains the best choice for most analytical solutions because it delivers excellent performance, simpler DAX, and cleaner report design.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>learning</category>
      <category>writing</category>
      <category>analytics</category>
    </item>
    <item>
      <title>Excel: The Foundation of Every Data Scientist's Journey</title>
      <dc:creator>Brayan Wafula</dc:creator>
      <pubDate>Sun, 30 Aug 2026 07:57:32 +0000</pubDate>
      <link>https://dev.to/brayan_wafula_2c36816f4c3/excel-the-foundation-of-every-data-scientists-journey-4of7</link>
      <guid>https://dev.to/brayan_wafula_2c36816f4c3/excel-the-foundation-of-every-data-scientists-journey-4of7</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In todays times, raw data is as precious if not more precious than oil, but it is rarely useful alone. it is a foundational tool in the data science field serving as as a primary interface for data organization, cleaning and manipulation. &lt;/p&gt;

&lt;p&gt;excel is not just a simple tool as it appears on the surface, it is a unique tool that can be used for various uses when it comes into contact with raw data. It allows users to &lt;em&gt;organize datasets&lt;/em&gt;, &lt;em&gt;identify errors&lt;/em&gt;, &lt;em&gt;remove duplicates&lt;/em&gt;, &lt;em&gt;standardize values&lt;/em&gt;, &lt;em&gt;perform calculations&lt;/em&gt; and &lt;em&gt;clean unorganized data&lt;/em&gt;(&lt;strong&gt;dirty data&lt;/strong&gt;). Once mastered excel becomes a skill on its own hence these skill are the foundation of professional data analytics.&lt;/p&gt;

&lt;p&gt;With Raw data being a gold mine across every department in each institution a tool is needed to help facilitate the organization and sorting of the data hence, this is where excel comes in. So we ask ourselves: &lt;/p&gt;

&lt;h3&gt;
  
  
  What is Excel?
&lt;/h3&gt;

&lt;p&gt;Excel is a tool created by Microsoft that help in simplifying data storage, cleaning and manipulation. Excel is an accumulation of one or more related worksheet. The worksheet is made up of different parts that comprise of it and some of them are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Quick Access Toolbar&lt;/strong&gt;: A small, customizable group of buttons for frequent actions like &lt;em&gt;save&lt;/em&gt;, &lt;em&gt;undo&lt;/em&gt; and &lt;em&gt;redo&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ribbon&lt;/strong&gt;: The main toolbar containing organized command tabs like &lt;em&gt;Home&lt;/em&gt;, &lt;em&gt;Insert&lt;/em&gt;, and &lt;em&gt;Page Layout&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Name box&lt;/strong&gt;: Located on the left below the ribbon, it shows the address  of your active cell.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Formular Bar&lt;/strong&gt;: The long input line next to the Name Box used to view, type or edit cell formulas and data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Active cell&lt;/strong&gt;: The current, individual box where data, text or formulas are being entered.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Column:&lt;/strong&gt; Vertical blocks of cells identified by letters running across the top (A,B,C...).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Row&lt;/strong&gt;: Horizontal blocks of cell identified by numbers running down the left side(1,2,3...).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Worksheet Tab&lt;/strong&gt;: Located at the bottom left, letting you switch between or add new worksheets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Title Bar&lt;/strong&gt;: The very top bar displaying the current file name and software controls.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Below is an image depicting an excel worksheet and some of its components:-&lt;/em&gt;   &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkz75ahmiohbbfglxmcc0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkz75ahmiohbbfglxmcc0.jpg" alt="Excel Parts" width="641" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Common Uses for Excel
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data Entry and Management&lt;/strong&gt;: Store lists, contact information, inventory, or raw numbers in an organized grid. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calculations and Formulas&lt;/strong&gt;: Use basic math(addition, subtraction,...) or built-in functions(like &lt;code&gt;SUM&lt;/code&gt; or &lt;code&gt;AVERAGE&lt;/code&gt;) to process numbers automatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Budgeting and Finance&lt;/strong&gt;: Track monthly expenses, build financial forecast, and manage business or personal accounts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Analysis&lt;/strong&gt;: Sort, filter and summarize large data sets using pivot tables and conditional formatting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Project Management&lt;/strong&gt;: Track timelines, task statuses, team resources, and project costs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Features of Excel
&lt;/h3&gt;

&lt;p&gt;Excel as a versatile tool is composed of different features that help it execute various commands. &lt;br&gt;
Some features are:-&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Conditional Formatting:&lt;/strong&gt; Used to alter, filter and highlight important information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Charts and Graphs&lt;/strong&gt;: Used as a visual aid in data representation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Worksheets&lt;/strong&gt;: Used in data organization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Formulas and functions&lt;/strong&gt;: Used in mathematical calculations. Some example of formulas and functions are;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;=SUM&lt;/em&gt;- Use for addition&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;=AVERAGE&lt;/em&gt;- Used to find the average number in a data set&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;=MAX&lt;/em&gt;- Used to find highest number&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;=MIN&lt;/em&gt;- Used to find lowest number&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;=COUNT&lt;/em&gt;- Used to count number of entries.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;The following is an example of formulas and functions as applied in excel&lt;/em&gt;; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Formula&lt;/strong&gt;
&lt;code&gt;=K3+I9&lt;/code&gt; 
&lt;code&gt;=B7+F8&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Function&lt;/strong&gt; 
&lt;code&gt;=SUM(I6+F4)&lt;/code&gt;
&lt;code&gt;=AVERAGE(A4:F4)&lt;/code&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Data Manipulation
&lt;/h2&gt;

&lt;p&gt;This is the changing, organizing, structuring, and cleaning or raw data to make it easier to analyze.&lt;br&gt;
Given a small dataset here is how data manipulation is done:&lt;br&gt;
&lt;em&gt;figure 1: An excel worksheet containing raw data with common data issues.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg18if083u3k2sx1aeasl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fg18if083u3k2sx1aeasl.png" alt="Raw data" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;some of the problems it has are extra spaces, different letter cases, missing values, duplicate rows and mixed data formats. A data analyst's first responsibility is to correct these issues.&lt;/p&gt;
&lt;h3&gt;
  
  
  Data Cleaning
&lt;/h3&gt;

&lt;p&gt;This is the process of finding and fixing errors, duplicates, and missing values in a dataset to make it accurate and ready for analysis.&lt;/p&gt;
&lt;h4&gt;
  
  
  Text Cleaning with Excel Functions
&lt;/h4&gt;

&lt;p&gt;Excel provides several powerful functions that aid in text cleaning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TRIM()&lt;/strong&gt;- Used to remove unnecessary spaces. &lt;strong&gt;Formula:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;=TRIM(B2)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PROPER()&lt;/strong&gt;- Converts names into proper capitalization. &lt;strong&gt;Formula:&lt;/strong&gt; &lt;code&gt;=PROPER(B2)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPPER()&lt;/strong&gt; and &lt;strong&gt;LOWER()&lt;/strong&gt;- Useful for standardizing codes or emails&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=UPPER(D2)
=LOWER(F2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Handling Missing values
&lt;/h4&gt;

&lt;p&gt;Missing information is detrimental to data analysis and results yielded. There are several  ways to fill missing values:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Manual correction using Known information.&lt;/li&gt;
&lt;li&gt;Fill Down for repeated values&lt;/li&gt;
&lt;li&gt;using find and replace &lt;/li&gt;
&lt;li&gt;IF formulas for  conditional replacements.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=IF(D2="", "Unknown", D2)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;replaces blank cells with unknown.&lt;/p&gt;

&lt;h4&gt;
  
  
  Removing Duplicate Records
&lt;/h4&gt;

&lt;p&gt;Duplicate are repeating records on the same worksheet. They may lead to incorrect or misleading reports. &lt;br&gt;
go to the &lt;strong&gt;ribbon&lt;/strong&gt; go to the &lt;strong&gt;Data Tab&lt;/strong&gt; then &lt;strong&gt;Remove duplicates&lt;/strong&gt;. After removal every entry appears only once.&lt;/p&gt;

&lt;h4&gt;
  
  
  Formatting Dates
&lt;/h4&gt;

&lt;p&gt;Dates are important for reports, dashboards and trend analysis. Excel stores dates as serial numbers internally, allowing calculations using functions such as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- TODAY()&lt;/strong&gt;: Returns the current date, which updates automatically every day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- NOW()&lt;/strong&gt;: Returns both the current date and time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- DATE(year, month, day)&lt;/strong&gt;: Creates a valid Excel date by combining individual year, month, and day values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- YEAR, MONTH, DAY&lt;/strong&gt;: Extracts the specific year, month number (1–12), or day number (1–31) from a given date.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flmy6dehrg746s338decp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flmy6dehrg746s338decp.png" alt="Time" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Sorting and Filtering Data
&lt;/h4&gt;

&lt;p&gt;Sorting helps organize information, while filtering isolates specific records. Examples;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Highest to smallest&lt;/li&gt;
&lt;li&gt;Smallest to Highest&lt;/li&gt;
&lt;li&gt;Newest to Oldest &lt;/li&gt;
&lt;li&gt;Oldest to Newest
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdaihr3xk5you5kyybmu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdaihr3xk5you5kyybmu9.png" alt="Sorting and Filtering" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating Calculated Columns
&lt;/h4&gt;

&lt;p&gt;A calculated column generated new information from existing fields.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fal95mctz0cp7jfmamij0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fal95mctz0cp7jfmamij0.png" alt="Calculated fields" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Final Cleaned Dataset
&lt;/h3&gt;

&lt;p&gt;After applying all cleaning techniques, the dataset becomes reliable and analysis ready.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzb9rwcm64m48pyd8euhf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzb9rwcm64m48pyd8euhf.png" alt="Final Data" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The cleaned version can now be used for creating PivotTables, dashboards, charts and further statistical analysis.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Cleaning in Analytics
&lt;/h3&gt;

&lt;p&gt;Data cleaning takes the most part of an analyst's time because poor-quality data leads to major issues(&lt;em&gt;inaccurate forecast&lt;/em&gt;, &lt;em&gt;wrong reports&lt;/em&gt;, &lt;em&gt;misleading visualization&lt;/em&gt;,...).&lt;/p&gt;

&lt;p&gt;Excel fundamentals acts as skills that can be directly transferred to other professional tools such as &lt;strong&gt;Power BI&lt;/strong&gt;, &lt;strong&gt;SQL&lt;/strong&gt;, &lt;strong&gt;Python&lt;/strong&gt;,.... The logic and basics remain the same: identify errors, standardize data, validate quality, and prepare datasets for meaningful analysis.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Excel functions learned
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TRIM()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Remove extra spaces&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;PROPER()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Proper capitalization&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UPPER()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Convert to uppercase&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;LOWER()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Convert to lowercase&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;IF()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replace missing values conditionally&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;TODAY()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Calculate date differences&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Calculate total revenue&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Excel is an excellent starting point for anyone entering data science and analytics. Although advanced tools like &lt;strong&gt;Python&lt;/strong&gt; and &lt;strong&gt;SQL&lt;/strong&gt; offer greater automation, Excel remains one of the most widely used applications for data preparation in businesses around the world.&lt;/p&gt;

&lt;p&gt;These are not merely spreadsheet skills—they are essential analytical practices that ensure data is accurate, consistent, and ready for decision-making.&lt;/p&gt;

&lt;h2&gt;
  
  
  Career Benefits
&lt;/h2&gt;

&lt;p&gt;Excel accelerates career growth by &lt;em&gt;boosting daily productivity&lt;/em&gt;, &lt;em&gt;increasing earning potential&lt;/em&gt; and &lt;em&gt;making the user a more competitive candidate across multiple industries&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Excel being a universal accepted application, it creates a competitive edge among users and it also improves efficiency and automation. Hence:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Save Time&lt;/strong&gt;: Formula and Functions update data automatically, removing the need for manual recalculations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automate tasks&lt;/strong&gt;: Macros handle repetitive formatting and report generation, reducing human error.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Better Organization&lt;/strong&gt;: Large and small datasets stay clean, structured,  and easy to filter in a single workbook.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Access to Specialized Roles
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Finance and Accounting&lt;/strong&gt;: Mastery enables precise financial modeling, budgeting and forecasting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Project Management&lt;/strong&gt;: Spreadsheets help in tracking timelines, allocate resources and document progress.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Analysis&lt;/strong&gt;: Power Query and Dashboards turn raw data into strategic business insight.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Education&lt;/strong&gt;: Excel help in storing students, teachers, staffs information to ease data storage, manipulation, retrieval and representation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;As a beginner, mastering these Week 1 concepts provides a strong foundation for more advanced topics such as PivotTables, dashboards, Power BI, SQL, and machine learning. The quality of every analysis begins with the quality of the data, and Excel is where that journey starts.&lt;/p&gt;

&lt;p&gt;Mastering Excel itself is a skill that can be used to gain different opportunities in different areas and can also be monetized as a skill on its own.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"&lt;em&gt;The goal is to turn data into information, and information into insight&lt;/em&gt;.”&lt;br&gt;
— &lt;em&gt;Carly Fiorina, former CEO of Hewlett-Packard&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>beginners</category>
      <category>datascience</category>
      <category>data</category>
      <category>career</category>
    </item>
    <item>
      <title>Understanding the Git Workflow: A Data Science Version Control Practical Guide</title>
      <dc:creator>Brayan Wafula</dc:creator>
      <pubDate>Sun, 23 Aug 2026 08:52:59 +0000</pubDate>
      <link>https://dev.to/brayan_wafula_2c36816f4c3/understanding-the-git-workflow-a-data-science-version-control-practical-guide-2h2</link>
      <guid>https://dev.to/brayan_wafula_2c36816f4c3/understanding-the-git-workflow-a-data-science-version-control-practical-guide-2h2</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Data science projects are usually a collaboration of different intertwined parts that are joined together to give a complete project and not just written code, it includes a dataset, python scripts, Sql queries, visualizations and documentation. As changes are done on these files tracking the different modifications becomes important. This is where Git becomes one of the most valuable tools for a data scientist.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Git, Git Bash and GitHub?
&lt;/h3&gt;

&lt;p&gt;Git is a software developed to help the user to keep track of changes to their code files while git bash is the command-line window akin to the windows terminal command prompt that is used by users to type out their commands. While, GitHub is an online (cloud-based) platform that creates an environment for users to work together  on projects and it also used to host computer code.&lt;/p&gt;

&lt;p&gt;Rather than Git being understood as simply a way to pass code from user to GitHub, it is better thought of as a library that keeps records of the history of your project from start to finish. Git is used to manage the project locally on the computer while GitHub stores it online. It is also understood or can also be called a version control system that allows the user to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Experiment freely&lt;/li&gt;
&lt;li&gt;Return to previous versions&lt;/li&gt;
&lt;li&gt;Collaborate with others&lt;/li&gt;
&lt;li&gt;Maintain an organized workflow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;The image is an example of a Git Bash terminal:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzvcvhiuubnmupeqjhrlu.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzvcvhiuubnmupeqjhrlu.webp" alt=" " width="743" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The image below is an example of a GitHub platform:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7wstj2nf9lh2u644zx7m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7wstj2nf9lh2u644zx7m.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Uses of Git, Git Bash and GitHub.
&lt;/h3&gt;

&lt;p&gt;Git being a version control system is used for various reasons. some of it uses are as listed below:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Tracking file history - Using commits(screenshots) it allows the user to return to previous versions in case something happens, tracks bugs an changes over time. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Team collaboration - It merges work done by different people and keep track of which changes were done by which user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Offline local work - Because Git is well distributed, every user has a copy of the the project being worked on their personal computer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Parallel Development - It works on different things at the same time without interfering with the main codebase.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Uses of Git Bash are as follows&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Running Git commands - Serves as a terminal that is used to execute commands like &lt;code&gt;git init&lt;/code&gt;, &lt;code&gt;git commit&lt;/code&gt;, &lt;code&gt;git push&lt;/code&gt;, &lt;code&gt;git pull&lt;/code&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enabling Unix/Linux commands on windows - Windows having its own inbuilt terminal (Power Shell and Command Prompt) it uses different syntaxes hence Git Bash brings standard Unix utilities like &lt;code&gt;cd&lt;/code&gt;, &lt;code&gt;ls&lt;/code&gt;, &lt;code&gt;mkdir&lt;/code&gt;, &lt;code&gt;pwd&lt;/code&gt; just to name a few  directly to windows.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running shell scripts - It enables users to write and run automated automation tasks using standard  Bash script files(&lt;code&gt;.sh&lt;/code&gt;) on a windows machine.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Universal tutorial compatibility - It allows Windows users to follow along with Linux on macOs terminal instructions exactly.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Uses of GitHub?&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
It being a cloud based platform and it having many features it is used for the following :&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Repositories - Also known as Repo(s), It is a storage folder where project code and history are found.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Version Control - A system that saves snapshots of code so you undo mistakes or compare old versions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Branching &amp;amp; Merging - Creating a separate copy of code to test a new idea and then recombining it with the main project if it works.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pull Requests - A request to review and merge code changes into a shared project.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h5&gt;
  
  
  Basic/Most Used Bash Commands
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;ls&lt;/code&gt; - Used to list files and folders&lt;br&gt;
&lt;code&gt;cd&lt;/code&gt; - Change directory&lt;br&gt;
&lt;code&gt;pwd&lt;/code&gt;  Find the path of the current directory&lt;br&gt;
&lt;code&gt;mkdir&lt;/code&gt; - Make a directory &lt;br&gt;
&lt;code&gt;mv&lt;/code&gt; - Move files and folders&lt;br&gt;
&lt;code&gt;rm&lt;/code&gt; - remove files and folders&lt;/p&gt;
&lt;h2&gt;
  
  
  The Git Workflow
&lt;/h2&gt;

&lt;p&gt;The Git workflow is a recipe or recommendation on how to use Git to manage code changes in a consistent, collaborative way.&lt;br&gt;
&lt;em&gt;It has four main stages, namely:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Working Directory&lt;/strong&gt;&lt;br&gt;
It is where the user actively works on their project. It is the computer local space where you create, edit and delete files. Changes made here aren't yet tracked by Git.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Staging Area(Index)&lt;/strong&gt;&lt;br&gt;
Think of this as a &lt;strong&gt;preparation space&lt;/strong&gt;. When the user has made changes they'd like to include in their next commit, they "stage" those changes, adding them to the staging area. Only staged chances make it to the next commit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Creating a Commit&lt;/strong&gt;&lt;br&gt;
A commit is a like a checkpoint in the user's project's history. Every commit usually describes a noteworthy change.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Create a commit:&lt;/em&gt;&lt;br&gt;
&lt;code&gt;git commit -m "Add patient age"&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Commit as a checkpoint makes it easier to return to an earlier version if the new test fails or performs worse.&lt;/p&gt;

&lt;p&gt;To view previous commits use:&lt;br&gt;
&lt;code&gt;git log --oneline&lt;/code&gt;.       &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub: The Remote Repository&lt;/strong&gt;
A commit saves history locally but GitHub stores a copy online so it can be backed up and shared.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After creating commits:&lt;br&gt;
&lt;code&gt;git push origin main&lt;/code&gt;&lt;br&gt;
Uploads your project to GitHub. &lt;/p&gt;

&lt;p&gt;If another team member adds new work, download  it using:&lt;br&gt;
&lt;code&gt;git pull origin main&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A common workflow is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull origin main
git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add patient age"&lt;/span&gt;
git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Essential Git Commands and Their Use Cases
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;git add&lt;/code&gt;&lt;br&gt;
It stages changes, preparing them for the next commit.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;: &lt;code&gt;git add &amp;lt;file&amp;gt;&lt;/code&gt; stages a specific file; &lt;code&gt;git add .&lt;/code&gt; stages all changes in the current directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: After editing &lt;code&gt;index.html&lt;/code&gt;, run &lt;code&gt;git add index.html&lt;/code&gt; to stage  the changes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;git status&lt;/code&gt;&lt;br&gt;
It  displays the state of your working directory and staging area, helping track which changes are staged, unstaged, or untracked. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;: Simply run &lt;code&gt;git status&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: After modifying &lt;code&gt;index.html&lt;/code&gt;, &lt;code&gt;git status&lt;/code&gt; will show that the file has been modified and is ready to be staged.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;git commit&lt;/code&gt;&lt;br&gt;
It records your your staged changes into the local repository, creatin a snapshot of your project at that point in time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;: &lt;code&gt;git commit -m "Your commit message&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: After staging your changes, run &lt;code&gt;git commit -m "Fix header alignment"&lt;/code&gt; to commit them with a descriptive message.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;git reset&lt;/code&gt;&lt;br&gt;
It undoes changes by moving the HEAD  pointer and, optionally, modifying the index and working directory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;: &lt;code&gt;git reset HEAD &amp;lt;file&amp;gt;&lt;/code&gt; unstages a specific file; &lt;code&gt;git reset --hard HEAD~1&lt;/code&gt; resets the repository to the previous commit, discarding changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: If you accidentally staged &lt;code&gt;style.css&lt;/code&gt;, run &lt;code&gt;git reset Head style.css&lt;/code&gt; to unstage it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Caution&lt;/strong&gt;: Using &lt;code&gt;git reset --hard&lt;/code&gt; can permanently delete changes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;git revert&lt;/code&gt;&lt;br&gt;
It creates a new commit that undoes the changes changes of a specified commit, preserving the project history.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;: &lt;code&gt;git revert &amp;lt;commit&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: To undo the effects of a problematic commit, first identify its commit hash using &lt;code&gt;git log&lt;/code&gt;, then run &lt;code&gt;git revert &amp;lt;commit-harsh&amp;gt;&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: It is safe for undoing changes in shared repositories, as it doesn't alter the commit history.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Visualization of the Git Workflow
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Start]
   |
   v
[Working Directory]
   |
   v
[git status] ---&amp;gt; [git add &amp;lt;file&amp;gt;] ---&amp;gt; [git commit -m "message"] ---&amp;gt; [git push origin main]
   |
   v
[Staging Area]
   |
   v
[Local Repository]
   |
   v
[Remote Repository]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;A Practical Workflow&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Create a hospital data model.&lt;br&gt;
&lt;strong&gt;Step 1&lt;/strong&gt;: Start project&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git init&lt;/code&gt;&lt;br&gt;
Initialize Git inside the project folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Check changes&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git status&lt;/code&gt;&lt;br&gt;
Git identifies modified datasets and scripts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Stage completed work&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add scripts/
git add README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Save a checkpoint&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git commit -m "Add patients age"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Upload to GitHub&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git push origin main&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Importance of Git in data science
&lt;/h4&gt;

&lt;p&gt;It provides several practical benefits beyond version control.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reproducibility:&lt;/strong&gt;&lt;br&gt;
Every step and model update is recorded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Experiment Tracking:&lt;/strong&gt;&lt;br&gt;
Compare different feature engineering or model versions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collaboration:&lt;/strong&gt;&lt;br&gt;
Multiple analysts can contribute without overwriting each other's work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backup:&lt;/strong&gt;&lt;br&gt;
Project remain safe even if a local computer fails.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Documentation:&lt;/strong&gt;&lt;br&gt;
Commit history tells the story of how the project evolved&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Essential Git commands
&lt;/h5&gt;

&lt;p&gt;&lt;code&gt;git init&lt;/code&gt; -Initialize a Git repository&lt;br&gt;
&lt;code&gt;git status&lt;/code&gt; - Check modified and staged files&lt;br&gt;
&lt;code&gt;git add&lt;/code&gt; - Stage all changes&lt;br&gt;
&lt;code&gt;git add filename&lt;/code&gt; - Stage a specific file&lt;br&gt;
&lt;code&gt;git commit -m "message"&lt;/code&gt; - Save a project checkpoint&lt;br&gt;
&lt;code&gt;git log --oneline&lt;/code&gt; - View commit history&lt;br&gt;
&lt;code&gt;git pull origin main&lt;/code&gt; - Download latest changes&lt;br&gt;
&lt;code&gt;git push origin main&lt;/code&gt; - Upload commits to GitHub&lt;br&gt;
&lt;code&gt;.gitignore&lt;/code&gt; - It is used to stop certain files from committing automatically. Should automatically be in a repo when creating a project.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Tips&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;&lt;em&gt;- Use &lt;code&gt;git status&lt;/code&gt; frequently to understand what's changed.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;- Stage only what you what to commit. &lt;code&gt;git add -p&lt;/code&gt; enables selective staging of file changes.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;- Write clear commit message to document why changes were made.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;- Commit often, but meaningful.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;The Git workflow is a simple but powerful process that moves changes through stages ( working Directory --&amp;gt; Staging Area --&amp;gt; Commit --&amp;gt; GitHub) for collaboration and backup. For data scientists, this workflow ensures the experiment remains organized, reproducible, and easy to manage throughout the project lifecycle.&lt;/p&gt;

&lt;p&gt;Mastering these four stages builds a strong foundation for collaborative analytics, machine learning development, and and professional software engineering practices in data science.&lt;/p&gt;

&lt;p&gt;As i finish let me leave you with&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The journey of a thousand miles begins with a single step."&lt;br&gt;
-Lao Tzu&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>beginners</category>
      <category>git</category>
      <category>github</category>
      <category>career</category>
    </item>
  </channel>
</rss>
