Lesson 27: The INNER JOIN (Standard Join)
The INNER JOIN is the most common type of join. It returns only the rows that have matching values in both tables.
Logic of the INNER JOIN
If a record in Table A does not have a corresponding record in Table B (or vice versa), it is excluded from the result set.
Example: Customers and Orders
We only want to see orders that are successfully linked to an existing customer.
sql SELECT O.OrderID, O.OrderDate, C.CustomerName -- Retrieving the name from the Customer table FROM Orders O -- Table Alias 'O' INNER JOIN Customers C -- Table Alias 'C' ON O.CustomerID = C.CustomerID; -- Linking condition (FK=PK)
Practical Application
- If Customer ID 10 exists but has no orders, they will not appear.
- If an order somehow references Customer ID 999 (which doesn't exist), that order will not appear.
Result: A clean set of data where the relationship is validated.