1. Home
  2. Blog
  3. Databases & SQL

Databases & SQL

SQL Joins Explained With Examples (Inner, Left, Right, Full)

Learn INNER, LEFT, RIGHT, FULL, CROSS and SELF joins with two tiny tables, clear queries and the exact results you should expect.

8 min read
SQL joins explained with examples: inner, left, right, full, cross and self joins

Key takeaways

  • INNER JOIN: only rows that match in both tables.
  • LEFT JOIN: all rows from the left table, plus matches (NULL if none).
  • RIGHT JOIN: all rows from the right table, plus matches.
  • FULL JOIN: all rows from both tables, matched where possible.
  • Join on keys, use table aliases and index the join columns.

Real databases never keep everything in one table. Customers live in one table and orders in another. To answer “which customers placed orders this month?” you must combine them, and that is what SQL joins explained in this guide covers.

This guide to SQL joins explained keeps everything practical. Joins confuse many beginners because the same two tables give different results depending on the join type. Once you see them with small, concrete data, they become easy.

SQL joins explained: the sample tables

customers

id name
1 Asha
2 Ben
3 Chitra

orders

id customer_id total
101 1 250
102 1 120
103 2 90
104 9 40

Chitra has no orders, and order 104 points to a customer (9) who does not exist. These two edge cases show the difference between the join types.

INNER JOIN

An INNER JOIN returns only rows where the condition matches in both tables. Rows without a partner are dropped.

SELECT c.name, o.id AS order_id, o.total
FROM customers c
INNER JOIN orders o ON o.customer_id = c.id;

Result: Asha (101), Asha (102), Ben (103). Chitra and order 104 are missing. Use it when you only care about related data, such as orders with their customer details. Plain JOIN means INNER JOIN.

LEFT JOIN

A LEFT JOIN keeps every row from the left table and adds matching rows from the right. Where there is no match, right-side columns are NULL.

SELECT c.name, o.id AS order_id, o.total
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;

Result: Asha (101), Asha (102), Ben (103), Chitra (NULL, NULL). Chitra now appears.

Quick tip: To find customers who never ordered, filter for NULL on the right side: WHERE o.id IS NULL returns Chitra. Testers use this to find orphaned or missing records.

RIGHT JOIN and FULL JOIN

A RIGHT JOIN mirrors a LEFT JOIN and keeps every row from the right table. Most people swap the table order and use LEFT JOIN because it reads more naturally.

SELECT c.name, o.id AS order_id
FROM customers c
RIGHT JOIN orders o ON o.customer_id = c.id;

The result includes order 104 with a NULL customer name. A FULL (OUTER) JOIN returns all rows from both tables: Chitra with no order and order 104 with no customer.

SELECT c.name, o.id AS order_id
FROM customers c
FULL OUTER JOIN orders o ON o.customer_id = c.id;

PostgreSQL and SQL Server support it. MySQL does not, so combine a LEFT JOIN and a RIGHT JOIN with UNION. For more on SQL joins explained, see the PostgreSQL manual page on table expressions and joins, and its joins tutorial.

Join Left-only rows Right-only rows Matches
INNER No No Yes
LEFT Yes No Yes
RIGHT No Yes Yes
FULL Yes Yes Yes

CROSS JOIN and SELF JOIN

A CROSS JOIN pairs every row of one table with every row of the other: three customers and four orders give twelve rows. It is rare, but useful for generating combinations such as test data for every size and colour.

SELECT c.name, o.id
FROM customers c
CROSS JOIN orders o;

A SELF JOIN joins a table to itself using aliases, for example to find each employee’s manager.

SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.id;

SQL joins explained: common mistakes and performance tips

  • Missing ON clause creates a CROSS JOIN by accident and explodes row counts.
  • Filtering the right table in WHERE after a LEFT JOIN turns it into an INNER JOIN; put the condition in the ON clause.
  • Ambiguous column names: prefix columns with table aliases.
  • Joining on non-unique columns multiplies rows and inflates totals.
  • Index the columns used in joins, select only the columns you need and check slow queries with EXPLAIN.

Why joins matter for testers

QA engineers use joins to verify that data created through the UI or an API landed correctly in the database, and to find orphan records. Pair this with our API testing with Postman guide. For the basics see the SQL tutorial for beginners, and for newer data stores read about vector databases. To run a database locally, see our Docker tutorial.

Final thoughts on SQL joins explained

SQL joins explained in one line: INNER keeps matches only, LEFT keeps everything on the left, RIGHT keeps everything on the right and FULL keeps all of it. Practise with two tiny tables until you can predict the result before running the query, then try joining three tables and combining joins with GROUP BY.

Frequently asked questions

What is the difference between INNER JOIN and LEFT JOIN?

INNER JOIN returns only matching rows from both tables. LEFT JOIN returns all rows from the left table and fills unmatched right-side columns with NULL.

Which SQL join is the fastest?

No join type is always fastest. Performance depends on indexes, table size and the query plan. Index join columns and check the execution plan.

Does MySQL support FULL OUTER JOIN?

No. In MySQL, combine a LEFT JOIN and a RIGHT JOIN with UNION to get the same result.

What is a self join used for?

A self join compares rows within the same table, such as finding each employee’s manager in a single employees table.

Why does my join return duplicate rows?

Duplicates usually appear when the join column is not unique in one of the tables. Check your keys or aggregate the data before joining.

Keep learning

Work with Stack Quora

Need help with testing, WordPress or SEO?

We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.

Keep reading

More guides on testing, AI & modern development

Enjoyed this article? Pick a topic and jump straight into our newest tutorials.

Databases & SQL

SQL GROUP BY and HAVING Explained With Examples

SQL GROUP BY and HAVING explained with sample tables, aggregate functions, WHERE vs HAVING and common mistakes, with queries you…

Read article →
Software Development

HTTP Status Codes Cheat Sheet for Developers and Testers

An HTTP status codes cheat sheet for developers and testers: every common 1xx to 5xx code, what it means and…

Read article →
Test Automation

Selenium WebDriver Waits Explained: Implicit, Explicit and Fluent

Selenium waits explained: implicit, explicit and fluent waits with Python examples, when to use each and how to remove flaky…

Read article →
Software Testing

Test Automation Mistakes Beginners Make and How to Avoid Them

The 10 test automation mistakes beginners make, from flaky waits to automating everything, and the practical fixes that keep your…

Read article →
Artificial Intelligence

Claude Opus 5.5 vs Sonnet 5.5: Pricing, Speed and When to Use Each

Claude Opus 5.5 vs Sonnet 5.5 compared: listed pricing, context, speed and a simple guide to which model fits coding,…

Read article →
Artificial Intelligence

Best AI Code Review Tools for Developers in 2026

Compare the best AI code review tools in 2026: CodeRabbit, GitHub Copilot, Qodo, Greptile and more. See what each does,…

Read article →
Software Development

What Is an API? A Simple Guide for Beginners

What is an API? Learn in plain English how APIs work, the main types, HTTP methods and status codes, with…

Read article →
Test Automation

Playwright Locators Cheat Sheet With Examples

A practical Playwright locators cheat sheet: getByRole, getByText, getByLabel, test IDs, CSS, filtering and chaining, with copy-paste examples for stable…

Read article →
Software Testing

How to Write Test Cases: Format, Examples and Best Practices

Learn how to write test cases with a clear format, login and checkout examples, a reusable template and best practices…

Read article →
Artificial Intelligence

Gemini 4 Argon: What’s New and How It Compares to Earlier Gemini Models

Gemini 4 Argon is Google's new flagship reasoning model. See its API limits, app features, coding focus and how to…

Read article →
Databases & SQL

SQL Joins Explained With Examples (Inner, Left, Right, Full)

SQL joins explained step by step with sample tables and queries: INNER, LEFT, RIGHT, FULL, CROSS and SELF joins, plus…

Read article →
Software Development

Python Virtual Environment Tutorial: venv, pip and uv

Learn how to create, activate and manage a Python virtual environment with venv, pip and uv, including requirements files, .gitignore…

Read article →
Test Automation

Playwright vs Cypress in 2026: Which Should You Pick?

Playwright vs Cypress compared for 2026: browsers, languages, speed, debugging, parallel runs, CI and cost. Find out which end-to-end testing…

Read article →
Software Testing

Smoke Testing vs Sanity Testing: Differences With Real Examples

Smoke testing checks that a build is stable enough to test. Sanity testing checks that a specific fix works. Learn…

Read article →
Artificial Intelligence

Claude Haiku 5.5: Features, Pricing and Use Cases for Developers

Claude Haiku 5.5 is Anthropic's fastest and lowest-priced model. See its 1M-token context, pricing, API changes and the best use…

Read article →
Software Testing

End to End Testing Best Practices: Boost Reliability in 2026

Flaky tests waste time and hide real bugs. Learn end to end testing best practices that make your tests stable,…

Read article →
Test Automation

Best Test Automation Framework 2026: Choose the Right One

Not sure which test automation framework to pick? Compare the main types, use a simple checklist, and see how Playwright,…

Read article →
Artificial Intelligence

AI Agents Best Practices: Deploy Reliable Intelligent Bots

AI agents can save hours of work, but only when they are built with care. Learn AI agents best practices…

Read article →
Test Automation

Test Automation Framework Example: Build a Scalable Suite

See a real test automation framework example with folder layout, page objects, test data and CI steps. Copy the structure…

Read article →
Software Testing

Best Test Automation Tools 2026: Top Picks for QA Teams

Compare the best test automation tools in 2026 for web, mobile and API testing. See what each tool does well,…

Read article →
Software Development

REST API Best Practices 2026: Build Scalable Services

Learn REST API best practices for 2026: clear URLs, correct status codes, versioning, pagination, security and error handling, with simple…

Read article →
Artificial Intelligence

MCP Stateless Architecture: What’s New in MCP 2026

The MCP 2026-07-28 spec removes sessions and the handshake. See how stateless MCP works, what breaks, what gets easier to…

Read article →
Artificial Intelligence

WebMCP Explained: How AI Agents Will Interact With Websites

WebMCP lets a website publish tools that AI agents can call directly. Learn the Declarative and Imperative APIs, code examples,…

Read article →
Databases & SQL

SQL Tutorial for Beginners: Complete Guide to SQL in 2026

Learn SQL from scratch. Create tables, insert and query data, filter, sort, group, join tables and use subqueries and indexes,…

Read article →
Software Development

Git Tutorial for Beginners: Complete Guide to Git and GitHub in 2026

Learn Git from zero. Create repositories, commit, branch, merge, fix mistakes and work with GitHub pull requests, using simple commands…

Read article →
DevOps

Docker Tutorial for Beginners: Complete Guide to Docker in 2026

New to Docker? Learn containers, images, Dockerfiles, volumes, networks and Docker Compose with simple commands and a small project you…

Read article →
Databases & SQL

Vector Databases Explained: How Vector Search and AI Databases Work in 2026

Vector databases search by meaning, not just keywords. Learn embeddings, similarity search, HNSW indexes, pgvector and how to choose the…

Read article →
Software Testing

API Testing with Postman: A Complete Guide for Beginners and QA Testers

Learn API testing with Postman from scratch. Send requests, read status codes, add auth, write test scripts, build collections and…

Read article →
DevOps

GitHub Actions CI/CD: A Complete Guide to Automating Software Builds, Tests and Deployments

Learn GitHub Actions from scratch. Build a CI/CD workflow that runs tests, builds your app and deploys it, with simple…

Read article →