If we join two tables with an inner join, how many records will result? How many combinations will be produced?
💡 Model Answer
The number of rows produced by an inner join depends on the cardinality of the join keys in each table. For each distinct key value that appears in both tables, the join creates a Cartesian product of the matching rows. If table A has n_a rows with key value k and table B has n_b rows with the same key k, the join will produce n_a × n_b rows for that key. The total result set is the sum of these products over all common key values. In the worst case, if every row in A matches every row in B (i.e., the join key is the same for all rows), the result will contain |A| × |B| rows. For example, joining a 1,000‑row customer table with a 5,000‑row orders table on customer_id could yield up to 5 million rows if every customer has orders. In practice, indexes on the join columns and filtering predicates reduce the actual number of combinations. Understanding this cardinality is crucial for performance tuning and estimating query cost.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.
Get Assisting AI — Starts at ₹500