SQL Table Relationships Explained
If SQL table relationships feel abstract or confusing, you’re not alone. Most explanations jump straight into diagrams and jargon without explaining the one thing that actually matters:
If you know where the foreign key goes, you understand the relationship.
This page will show you how to think about relationships, not just what they’re called — with plain-English explanations, simple diagrams, and copy-paste SQL examples.
The Only Rules You Need to Remember
Before we dive in, lock these in:
-
One-to-One (1:1) → Foreign key is unique
-
One-to-Many (1:N) → Foreign key goes on the many side
-
Many-to-Many (N:N) → You must use a junction table
If you remember nothing else, remember this.
One-to-One (1:1)
What it means
Each row in Table A relates to one and only one row in Table B.
When it’s used
-
Optional or extended data
-
Sensitive data separation
-
Keeping tables smaller and cleaner
Real-world example
A user has one profile.
A profile belongs to one user.
Where does the foreign key go?
✅ The foreign key is unique
Often it’s also the primary key.
Example tables
SQL example
Common mistake
❌ Forgetting to enforce uniqueness, which silently turns this into one-to-many.
One-to-Many (1:N)
What it means
One row in Table A can relate to many rows in Table B — but each row in Table B belongs to only one row in Table A.
This is the most common relationship in SQL.
Real-world example
A user can write many posts.
Each post belongs to one user.
Where does the foreign key go?
✅ Always on the many side
Example tables
SQL example
Why this works
Each post “knows” which user it belongs to.
The user doesn’t need to track all its posts.
Common mistake
❌ Storing multiple post IDs inside the users table.
Many-to-Many (N:N)
What it means
Rows in Table A can relate to many rows in Table B — and rows in Table B can relate to many rows in Table A.
Important rule
🚨 This cannot exist without a third table.
Real-world example
Students take many courses.
Courses have many students.
The junction (pivot) table
The middle table holds both foreign keys.
SQL example
Why the extra table exists
SQL tables store rows, not lists.
The junction table turns relationships into data.
Common mistake
❌ Trying to store arrays or comma-separated IDs.
Quick Mental Models
-
One-to-One → “Extra details”
-
One-to-Many → “Ownership”
-
Many-to-Many → “Membership / tagging / access”
Cheat Sheet (Save This)
-
1:1 → FK is unique
-
1:N → FK on the many table
-
N:N → Junction table with 2 FKs + composite PK
If you can point to the foreign key and explain why it lives there, you understand SQL relationships.