Free · 3 minutes · no registration Your IT profession: Backend developer? Find the profession that suits me
1 December 2026

SQL JOIN types: INNER, LEFT, RIGHT and FULL JOIN with Oracle examples

SQL JOIN types: INNER, LEFT, RIGHT and FULL JOIN with Oracle examples

Most people who start learning SQL quickly get the hang of pulling data from a single table, but once two or more tables come into play, the confusion begins: why did some rows disappear from the result, why does the same row show up several times, and when should you use a LEFT JOIN? In real databases, data is almost always split across several tables, so understanding SQL JOIN types is a core skill for everyday work as well as for job interviews and certification exams. In this article, we walk through INNER, LEFT, RIGHT, FULL and CROSS JOIN, as well as self-joins, step by step using one simple example and Oracle SQL syntax.

What is a JOIN and why do you need it?

In a relational database, data is stored in separate tables to avoid duplication. For example, the department name isn't repeated in every employee row: the employees table only holds the department ID (dept_id), while the department name lives in a separate table. A JOIN lets you combine these tables on a shared column to produce a single result.

All the examples use the following two small tables:

DEPARTMENTS
dept_id | dept_name
--------+-----------
10 | IT
20 | Finance
30 | Marketing

EMPLOYEES
emp_id | name | dept_id | manager_id
-------+--------+---------+-----------
1 | Aysel | 10 | NULL
2 | Rauf | 20 | 1
3 | Nigar | 10 | 1
4 | Elvin | NULL | 3

Note that Elvin isn't assigned to any department, and nobody works in Marketing. These two "edge" cases are exactly what will make the differences between JOIN types clear.

INNER JOIN: only matching rows

An INNER JOIN returns the rows that satisfy the join condition in both tables. Rows without a match are left out of the result.

SELECT e.name, d.dept_name
FROM employees e
JOIN departments d ON e.dept_id = d.dept_id;

The result has three rows: Aysel – IT, Rauf – Finance, Nigar – IT. Elvin doesn't appear because his dept_id is NULL, and Marketing doesn't appear because no employees belong to it. By the way, writing just JOIN is the same as INNER JOIN.

An important point: NULL isn't considered "equal" to any value, not even another NULL. That's why rows with NULL in the join column never match on an equality condition.

LEFT OUTER JOIN: all rows from the left table

A LEFT JOIN keeps every row from the table on the left and adds only the matching rows from the right table. Where there's no match, the right table's columns are filled with NULL.

SELECT e.name, d.dept_name
FROM employees e
LEFT JOIN departments d ON e.dept_id = d.dept_id;

The result has four rows: the three rows from the INNER JOIN plus Elvin – NULL. This query is a good fit for tasks like "list all employees, including those without an assigned department."

LEFT JOIN also has a very handy use: finding rows that have no match.

SELECT e.name
FROM employees e
LEFT JOIN departments d ON e.dept_id = d.dept_id
WHERE d.dept_id IS NULL;

This query returns only Elvin. It's the standard way to find employees who don't have a department.

RIGHT and FULL OUTER JOIN

RIGHT JOIN

A RIGHT JOIN is the mirror image of a LEFT JOIN: all rows from the right table are kept.

SELECT e.name, d.dept_name
FROM employees e
RIGHT JOIN departments d ON e.dept_id = d.dept_id;

The result is the three matching rows plus NULL – Marketing. In practice, many people prefer to swap the tables and write a LEFT JOIN instead of a RIGHT JOIN, since it's easier to read queries when they all go in the same direction. Both approaches give the same result.

FULL OUTER JOIN

A FULL JOIN returns all rows from both tables: matching rows are combined, and rows without a match are shown with NULL on the other side.

SELECT e.name, d.dept_name
FROM employees e
FULL OUTER JOIN departments d ON e.dept_id = d.dept_id;

The result has five rows: the three matching rows, Elvin – NULL and NULL – Marketing. This type is useful for comparing two lists, for example to find discrepancies between data in two systems.

CROSS JOIN: every row with every row

A CROSS JOIN pairs each row of the first table with each row of the second, without any join condition. This is a Cartesian product: in our example, it produces 4 × 3 = 12 rows.

SELECT e.name, d.dept_name
FROM employees e
CROSS JOIN departments d;

CROSS JOIN is rarely used on purpose, for example to generate every combination of products and sizes. But writing the old-style FROM employees, departments and forgetting the WHERE condition gives exactly the same result. On large tables, that means an unexpectedly huge number of rows and a slow query, so if your query returns suspiciously many rows, check the join condition first.

Self-join: joining a table to itself

Sometimes the relationship lives within a single table. In our example, the manager_id column refers to another employee's emp_id. To show each employee's manager next to their name, we join the table to itself using two different aliases:

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

Result: Aysel – NULL, Rauf – Aysel, Nigar – Aysel, Elvin – Nigar. We use a LEFT JOIN here so that Aysel, who has no manager, stays in the list. Aliases are essential in a self-join: without them, the database can't tell which "copy" of the table a column belongs to.

Oracle-specific syntax: USING, NATURAL JOIN and (+)

In Oracle SQL, and especially when preparing for certification exams, you'll also come across the following variants:

  • USING: if the join column has the same name in both tables, you can write JOIN departments USING (dept_id). Watch out: a column listed in USING can't be qualified with a table alias (like e.dept_id) anywhere in the query, or Oracle will throw an error.
  • NATURAL JOIN: automatically joins on all columns that share the same name in both tables. It looks convenient but is risky: if another column with a matching name is later added to a table, the join condition changes without you noticing.
  • The (+) operator: Oracle's legacy outer join syntax. WHERE e.dept_id = d.dept_id(+) is equivalent to a LEFT JOIN. You'll often see it in older projects, but Oracle recommends ANSI syntax (LEFT JOIN ... ON) for new code. Also, you can't write a FULL OUTER JOIN with (+).

Joining three or more tables

Real-world queries rarely stop at two tables. JOINs are written one after another, like a chain: each new JOIN combines the result of the previous step with the next table. For example, if there were a locations table storing the offices where departments are based, the query would look like this:

SELECT e.name, d.dept_name, l.city
FROM employees e
JOIN departments d ON e.dept_id = d.dept_id
JOIN locations l ON d.location_id = l.location_id;

One rule is worth remembering here: if you've used a LEFT JOIN somewhere in the chain and then write an INNER JOIN in a later step, the NULL rows preserved by the earlier LEFT JOIN can disappear again. So think through the type of each join in the chain separately.

Common beginner mistakes

  1. Filtering the right table in WHERE after a LEFT JOIN. For example, if you write LEFT JOIN departments d ON ... and then add WHERE d.dept_name = 'IT', rows with NULL fail the condition and the query effectively turns into an INNER JOIN. If you want to keep all rows from the left table, put the condition in the ON clause instead: ON e.dept_id = d.dept_id AND d.dept_name = 'IT'.
  2. Inflating results because of duplicated rows. In a one-to-many relationship (one department, many employees), the department row is repeated several times after the join. Aggregate functions like SUM or COUNT can then return larger results than expected.
  3. Writing column names without aliases. If both tables have a column with the same name and you reference it without an alias, Oracle returns a "column ambiguously defined" error. Using aliases consistently prevents both this error and hard-to-read code.
  4. Forgetting the join condition. As mentioned above, the result turns into a Cartesian product.

Which JOIN should you choose and when?

  • You only need records that have a match on both sides: INNER JOIN.
  • You need the entire main list, with extra details shown where available: LEFT JOIN.
  • You need to find records without a match: LEFT JOIN + WHERE ... IS NULL.
  • You need a full comparison of two lists: FULL OUTER JOIN.
  • You need every possible combination: CROSS JOIN.
  • The relationship is within a single table (manager – employee, category – subcategory): self-join.

One useful way to learn is to predict the result in advance: before running a query, write down on paper how many rows you expect and which columns will contain NULL, then check. This habit helps you catch mistakes quickly in real work and answer exam questions like "how many rows will this query return?" with confidence.

Conclusion

JOINs are one of the central topics in SQL: INNER JOIN shows matches, OUTER JOINs (LEFT, RIGHT, FULL) also show rows without a match, CROSS JOIN shows every combination, and a self-join shows relationships within a table. The key to remembering the differences is understanding how NULL behaves and checking each query's result on a small example. In an Oracle environment, USING, NATURAL JOIN and the legacy (+) syntax are added to the mix.

If you'd like to learn JOINs, subqueries, SET operators and DML/DDL statements systematically through hands-on exercises and prepare for the Oracle SQL certification, take a look at the 1Z0-071 Oracle Database SQL Certified Associate exam prep course.

Course programs

SMM – Social Media Marketing Courses

Help Desk courses

IT Service Management

1Z0-829 – Java SE 17 Developer (Java 17)

Network Administration Courses

Product Owner Courses

QA courses

Data analytics courses

Don't know where to start?

Apply

Complete your application for the chosen course and let us share our knowledge with you.

+994
+ Add a message

Your data is used only to contact you.

Contact us directly (+994 10) 234 65 56
  • Address
  • 609 Jafar Jabbarli St., Baku / Globus Center

  • Social networks