✏️ Explanatory Question

When to Use Inner Join

👁 20 Views
📘 Detailed Answer
🟢 Easy
No previous question
No next question
💡

Answer with Explanation

1. You Only Want Matching Records

If you're interested only in records that exist in both tables (i.e., the relationship exists), go for Inner Join.

Example: List all customers who have placed at least one order and include both customer and order data.


while select customer
    join salesTable
    where salesTable.CustAccount == customer.AccountNum
{
    // Returns only customers with matching sales orders
    // Both table data is available
}

2. You Need Data from Both Tables

Unlike Exists Join, which doesn’t return data from the joined table, Inner Join lets you fetch fields from both tables.


3. Standard Transactional Queries

Used heavily in reports, forms, and classes where you need:

  • Order + Customer

  • Product + Inventory

  • Project + Transactions


4. Ensuring Referential Integrity

Use it when your logic depends on records existing in both tables (e.g., linking foreign keys).

Example: Fetch all posted journals along with their respective voucher transactions.


✅ Summary Table:

Use Case Use Inner Join?
Need only matched records from both tables ✅ Yes
Need fields from both tables ✅ Yes
Need unmatched records from main table ❌ Use Outer Join
Need to filter main table based on child only ❌ Use Exists Join
Need to exclude records with child records ❌ Use NotExists Join
No previous question
No next question