Deep Dive into SQL Joins and Indexes

MEDIUM7 min readby AdminJune 19, 2026History
0.0|0 ratingsLog in to rate

Learn the differences between SQL joins (INNER, LEFT, RIGHT, FULL) and how database indexes speed up operations.

#dbms#sql#indexing#performance

Understanding SQL Joins

Joins combine rows from two or more tables based on a related column between them:

• INNER JOIN: Returns records that have matching values in both tables. • LEFT JOIN: Returns all records from the left table, and matching records from the right table. Fill missing values with NULL. • RIGHT JOIN: Returns all records from the right table, and matching records from the left table. • FULL JOIN: Returns all records when there is a match in either left or right table.

SQL Join Syntax

sql
1
2
3
4
5
6
SELECT 
  students.StudentName,
  enrollments.CourseName
FROM Students students
INNER JOIN Enrollments enrollments 
  ON students.StudentID = enrollments.StudentID;

How Indexes Speed Up Queries

Without indexes, databases perform a sequential scan (table scan), checking every single row, which is an O(N) operation.

An index is a separate data structure (usually a B-Tree or Hash Table) that stores pointers to rows sorted by the indexed column, enabling O(log N) searches.

However, indexing has tradeoffs:

  • Speeds up READS (SELECT queries with filters).
  • Slows down WRITES (INSERT, UPDATE, DELETE) since the index structure must be modified as well.
  • Consumes extra storage space.

Discussion

Join the discussion! Sign in to leave comments and ask questions.

Loading discussion...