Home › Interview Questions › How would you perform a join between these two tab…

How would you perform a join between these two tables using the primary key and foreign key columns?

🟡 Medium Conceptual Junior level
1Times asked
Sep 2026Last seen
Sep 2026First seen

💡 Model Answer

To join two tables using a primary key and foreign key, you first identify the key columns: the primary key in the parent table and the matching foreign key in the child table. For instance, if Table A has a primary key CustomerID and Table B has a foreign key CustomerID, you can write an SQL statement: SELECT FROM TableA a JOIN TableB b ON a.CustomerID = b.CustomerID. This inner join returns only rows where the keys match, effectively linking each customer to their orders. If you need all customers even those without orders, use a LEFT JOIN: SELECT FROM TableA a LEFT JOIN TableB b ON a.CustomerID = b.CustomerID. The join condition ensures referential integrity and prevents duplicate rows that would arise from a Cartesian product. Using PK/FK joins also allows the database engine to use indexes on the key columns, improving query performance. In summary, PK/FK joins are the standard way to combine related tables while preserving data integrity and optimizing performance.

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 on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500