Master SQL Joins: Inner, Outer, and Cross Join Explained with Examples
This article explains the three types of SQL joins—inner, outer, and cross—detailing their variations such as equi‑join, non‑equi‑join, natural join, left/right/full outer joins, and provides clear example queries and result illustrations to help readers understand how to combine tables effectively.
SQL Join Types Overview
SQL joins can be divided into inner join, outer join, and cross join.
1. Inner Join
1.1 Equi Join
An equi join uses the equality operator (=) in the join condition to compare column values, returning all columns from the joined tables, including duplicates.
1.2 Non‑Equi Join
A non‑equi join uses comparison operators other than = (such as >, >=, <, <=, !=, <>) in the join condition.
1.3 Natural Join
A natural join also uses = but automatically removes duplicate columns from the result set.
Inner join returns rows that satisfy the join condition by comparing column values.
select * from book as a, stu as b where a.sutid = b.stuid;
select * from book as a inner join stu as b on a.sutid = b.stuid;The INNER keyword can be omitted in the first syntax.
2. Outer Join
2.1 Left Join
A left join uses the left table as the base, matching rows where a.stuid = b.stuid and filling columns from the right table with NULL when there is no matching row.
select * from book as a left join stu as b on a.sutid = b.stuid;2.2 Right Join
A right join uses the right table as the base, matching rows where a.stuid = b.stuid and filling columns from the left table with NULL when there is no matching row.
select * from book as a right join stu as b on a.sutid = b.stuid;2.3 Full Outer Join
A full outer join returns all rows from both tables; when a row has no match in the other table, the missing side’s columns are NULL.
select * from book as a full outer join stu as b on a.sutid = b.stuid;3. Cross Join
A cross join returns the Cartesian product of the two tables, pairing each row of the left table with every row of the right table.
select * from book as a cross join stu as b order by a.id;Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
