The INNER JOIN is the most common join in database computing. It queries records from two or more tables and returns only the rows that satisfy the join condition in both tables. Any unmatched records on either side are completely omitted from the result set.
SELECT a.column1, b.column2
FROM table_a a
INNER JOIN table_b b ON a.key = b.key;
-- Join students and departments on dept_id
SELECT
s.student_id,
s.first_name,
d.dept_name,
s.gpa
FROM students s
INNER JOIN departments d ON s.dept_id = d.dept_id;
| student_id | first_name | dept_name | gpa |
|---|---|---|---|
| 1 | Aman | Engineering | 3.85 |
| 2 | Pooja | Business | 3.92 |
| 3 | Rohan | Engineering | 3.75 |
NULL dept_id) is excluded because NULL matches nothing.Next, let us learn how to keep all rows from the primary table using SQL LEFT OUTER JOIN!