<?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: Onyango Victor ochieng</title>
    <description>The latest articles on DEV Community by Onyango Victor ochieng (@onyango_victorochieng_f7).</description>
    <link>https://dev.to/onyango_victorochieng_f7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2796289%2F90d7427c-53dc-4495-a918-5ffa8de80682.png</url>
      <title>DEV Community: Onyango Victor ochieng</title>
      <link>https://dev.to/onyango_victorochieng_f7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/onyango_victorochieng_f7"/>
    <language>en</language>
    <item>
      <title>Introduction to Joins and Windows Funtions in SQL</title>
      <dc:creator>Onyango Victor ochieng</dc:creator>
      <pubDate>Wed, 04 Mar 2026 11:02:30 +0000</pubDate>
      <link>https://dev.to/onyango_victorochieng_f7/introduction-to-joins-and-windows-funtions-in-sql-469e</link>
      <guid>https://dev.to/onyango_victorochieng_f7/introduction-to-joins-and-windows-funtions-in-sql-469e</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Joins define relational operations that primarily combine data from multiple tables based on a logical relationship which in most cases is a foreign key, potentially increasing row counts and expanding columns. When working with databases, specifically normalized databases, it is a best practice to distribute data across multiple tables subsequently enforcing integrity and eliminating redundancy. The different types of joints include the &lt;em&gt;&lt;strong&gt;INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, and CROSS JOIN.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INNER JOIN&lt;/strong&gt;&lt;br&gt;
This is the default join type that returns only matching records from the referenced tables in the query.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;LEFT JOIN&lt;/strong&gt;&lt;br&gt;
Returns all rows from the left table (the first table) and matched rows from the right (second table), with NULLs for unmatched right-side rows.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;RIGHT JOIN&lt;/strong&gt;&lt;br&gt;
Returns all rows from the right table (the second table) and matched rows from the left (first table), with NULLs for unmatched left-side rows.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;FULL JOIN&lt;/strong&gt;&lt;br&gt;
This type of join returns all rows from both tables with non-matches on either side returned as null values.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;**CROSS JOIN&lt;br&gt;
**This is a special join type that allows users to produce a Cartesian product, pairing every row from the first table with every row from the second. However, when using this join you should be careful to avoid row explosion.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT s.full_name, c.course_name
FROM students s
CROSS JOIN courses c;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  WINDOWS FUNCTIONS
&lt;/h2&gt;

&lt;p&gt;SQL window functions enable calculations over a group of rows associated with the current row, while preserving each individual row in the result set rather than aggregating them into a single summary value. We can think of windows functions as commands to analyze rows around me without merging or removing rows. The different windows functions are commonly used for tasks like aggregates, running totals, and ranking as they provide a holistic view of the data.&lt;br&gt;
Below are the common SQL window functions presented in bullet format, organized by catego&lt;/p&gt;

&lt;h3&gt;
  
  
  Ranking Functions
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ROW_NUMBER()&lt;/strong&gt;&lt;br&gt;
Assigns a unique sequential number to each row within a partition&lt;br&gt;
No ties allowed&lt;br&gt;
&lt;strong&gt;RANK()&lt;/strong&gt;&lt;br&gt;
Assigns the same rank to tied values&lt;br&gt;
Skips rank numbers after ties&lt;br&gt;
&lt;strong&gt;DENSE_RANK()&lt;/strong&gt;&lt;br&gt;
Assigns the same rank to tied values&lt;br&gt;
Does not skip rank numbers&lt;/p&gt;

&lt;h3&gt;
  
  
  Aggregate Window Functions
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;SUM()&lt;/strong&gt;&lt;br&gt;
Calculates totals across a partition&lt;br&gt;
&lt;strong&gt;AVG()&lt;/strong&gt;&lt;br&gt;
Computes average values over a window&lt;br&gt;
&lt;strong&gt;COUNT()&lt;/strong&gt;&lt;br&gt;
Counts rows within a partition&lt;br&gt;
&lt;strong&gt;MIN()&lt;/strong&gt;&lt;br&gt;
Returns minimum value in a window&lt;br&gt;
&lt;strong&gt;MAX()&lt;/strong&gt;&lt;br&gt;
Returns maximum value in a window&lt;/p&gt;

&lt;h3&gt;
  
  
  Navigation (Value) Functions
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;LAG()&lt;/strong&gt;&lt;br&gt;
Retrieves value from a previous row&lt;br&gt;
&lt;strong&gt;LEAD()&lt;/strong&gt;&lt;br&gt;
Retrieves value from a following row&lt;br&gt;
&lt;strong&gt;FIRST_VALUE()&lt;/strong&gt;&lt;br&gt;
Returns the first value in a window&lt;br&gt;
&lt;strong&gt;LAST_VALUE()&lt;/strong&gt;&lt;br&gt;
Returns the last value in a window&lt;/p&gt;

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

&lt;p&gt;In summary, joins and window functions serve distinct yet complementary roles in SQL querying. Joins integrate data across related tables, enabling comprehensive relational analysis, while window functions enhance datasets with analytical insights without reducing row-level detail. Mastery of both concepts is essential for designing efficient queries, supporting advanced reporting, and performing meaningful data analysis in structured, normalized database environments.&lt;/p&gt;

</description>
      <category>database</category>
      <category>datascience</category>
      <category>luxdevhq</category>
      <category>dataengineering</category>
    </item>
  </channel>
</rss>
