MySQL INNER JOIN
The INNER JOIN
keyword selects records that have matching values in both tables. It is used to retrieve rows where there is a match between columns in both tables.
Example: Using INNER JOIN
SELECT tamil_kings.king_name, kingdoms.kingdom_name
FROM tamil_kings
INNER JOIN kingdoms ON tamil_kings.kingdom_id = kingdoms.kingdom_id;
Code Explanation: This query retrieves the names of kings along with their respective kingdoms where there is a match in kingdom_id
.
Key Takeaways
- Use
INNER JOIN
to combine rows from both tables where there are matching values. - Rows without matches in either table will not be included in the result.