Lexicon
⌘K
Explore
ExploreGuidesNotes
WriteMy Library
Sign in
Browse

Networking

  • OSI Model
  • TCP vs UDP
  • TCP/IP Model
  • Layer 2 & Layer 3 Networking

Programming

  • Start Here — How to Solve a Problem
  • From if/else to DSA — The Whole Path
  • Problem Solving
  • DSA Practice — Learn by Solving
  • C Programming
  • Python

Bug Bounty

  • Only Bug Bounty Checklist You'll Ever Need!!!
  • Only Bug Bounty Checklist You'll Ever Need!!! V2

My Notes

  • Python Conditional Statements - The Complete Breakdown
  • Python Data Types - The Complete Breakdown
  • Python Dictionaries - The Complete Breakdown
  • Python Exception Handling - The Complete Breakdown
  • Python Functions - The Complete Breakdown
  • Python Lists vs Arrays — The Real Story
  • Python Loops - The Complete Breakdown
  • Python OOP - The Complete Breakdown
  • The f Thing in Python - f-strings

Python

  • Python String Manipulation Functions - Full Reference
New noteSuggest a guide

Lexicon

a personal knowledge base

← Back to post

Version history

No earlier versions yet — history builds up each time this note is edited.

Current version1 of 1

SQL

SQL joins explained

A join combines rows from two tables based on a related column. The join type decides what happens to rows that have no match.

Sample tables

Say we have users and orders, where each order has a user_id.

INNER JOIN

Only rows that match on both sides.

SELECT u.name, o.total
FROM users u
INNER JOIN orders o ON o.user_id = u.id;

A user with no orders does not appear. An order with no matching user does not appear.

LEFT JOIN

Every row from the left table, plus matches from the right. Where there is no match, the right columns are NULL.

SELECT u.name, o.total
FROM users u
LEFT JOIN orders o ON o.user_id = u.id;

This is how you find users with no orders:

SELECT u.name
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE o.id IS NULL;

RIGHT JOIN and FULL JOIN

  • RIGHT JOIN is a LEFT JOIN with the tables flipped. Most people just rewrite it as a LEFT JOIN for readability.
  • FULL OUTER JOIN keeps unmatched rows from both sides, filling NULLs where there is no partner.

Mental picture

JoinKeeps
INNERonly matches
LEFTall left rows plus matches
RIGHTall right rows plus matches
FULLeverything from both

The classic bug

Filtering a LEFT JOIN in the WHERE clause on the right table quietly turns it into an INNER JOIN, because a NULL fails the comparison. If you want to keep unmatched rows, put the condition in the ON clause instead of WHERE.