1

I read from this answer (click), the following conditional statements

Invoices.CustomerID=Customers.CustomerID

and

Customers.CustomerID=Invoices.CustomerID

are identical because it produces the same result set.

Now, my problem is about commutativity of inner join. I have tried both of the following approaches and they produce the same result set (except for the column order).

Customers table first

use MMABooks
select *
from Customers
    inner join Invoices
on Invoices.CustomerID=Customers.CustomerID
where Customers.CustomerID=10

Invoices table first

use MMABooks
select *
from Invoices
    inner join Customers
on Invoices.CustomerID=Customers.CustomerID
where Invoices.CustomerID=10

Questions

  1. Is inner join commutative by design?
  2. Is there a best practice that suggest or prefer one approach over the other one? I mean, which approach should I use?
Community
  • 1
  • 1
kiss my armpit
  • 3,413
  • 1
  • 27
  • 50

1 Answers1

5

It would be really weird if they didn't produce the same result. Did you expect a difference?

A best practice is to start with the table from which you select most of the columns.

You do have to worry about the order when you work with LEFT or RIGHT JOINS.

wvdz
  • 16,251
  • 4
  • 53
  • 90