PostgreSQL INNER JOIN
An INNER JOIN
returns rows that have matching values in both tables. Rows without matches in either table are excluded from the result set.
Example
SELECT c.customer_id, c.first_name, o.order_id
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id;
Best Practices
- Use
INNER JOIN
when you only need rows that match in both tables. - Consider indexing the join columns for faster lookups.
Key Takeaways
INNER JOIN
excludes rows with no matching key in the other table.- Always specify the join condition with the
ON
clause.