SQL Server Interview Question #62
What is an INNER JOIN?
Joins, Subqueries, CTEs & Set Operators Mid-Level Intermediate
Quick Interview Answer
INNER JOIN returns only rows for which the join predicate finds a match on both sides.
For example, if Products.CategoryId references Categories.Id, an INNER JOIN returns products that have matching category rows. Rows without a matching counterpart are excluded from the result.
Detailed Explanation
INNER JOIN returns only rows for which the join predicate finds a match on both sides.
For example, if Products.CategoryId references Categories.Id, an INNER JOIN returns products that have matching category rows. Rows without a matching counterpart are excluded from the result.
Code Example
SELECT p.Id, p.Name, c.Name AS CategoryName
FROM dbo.Products AS p
INNER JOIN dbo.Categories AS c
ON p.CategoryId = c.Id;