DEV Community

Wickliff Odoyo
Wickliff Odoyo

Posted on

Mastering SQL Joins and Window Functions (With Clear Examples)

SQL Jpins and Windows functions

1.SQL JOINS

-Joins allow you to retrieve data from multiple tables based on a relationship between them.
-For example when you have motre than two tables to use,e.g project,employee and department table.

a.Inner join

-inner join is a join that return only matching records from both tables.

b.Left join

Returns all records from the left table and matching records from the right table.

c.Right join

Returns all records from the right table and matching from the left.

d.Full outer join

Returns everything from both tables.

e.cross join

-returns a combination of rows from both tables .

f.Self join

-joins table to itself

g.Natural join

-used to join both tables which returns all records from the tables.

2.WINDOW FUNCTIONS

-Window functions perform calculations across a set of rows without collapsing them like GROUP BY does.

1️⃣ ROW_NUMBER()

-Assigns a unique number to each row.


2️⃣ RANK()

Similar to ROW_NUMBER but handles ties.


3️⃣ SUM() OVER()

Calculates running totals.


4️⃣ Running Total

Top comments (0)