Does the order of the join ON clause matters?

Screen Link:

My Code:

Replace this line with your code
SELECT
   c.first_name || " " || c.last_name customer_name,
   COUNT(i.invoice_id) number_of_purchases,
   SUM(i.total) total_spent,
   CASE
       WHEN sum(i.total) < 40 THEN 'small spender'
       WHEN sum(i.total) > 100 THEN 'big spender'
       ELSE 'regular'
       END
       AS customer_category
FROM invoice i
INNER JOIN customer c ON c.customer_id = i.customer_id
GROUP BY 1 ORDER BY 1;

What I expected to happen:


What actually happened: 

Replace this line with the output/error


<!--Enter other details below: -->
Does the order on the ON clause of the INNER JOIN matter? 
ON c.customer_id = i.customer_id the same as i.customer_id = c.customer_id?

I had this same question before and Googled a lot before finding the answer: no, order does not matter since SQL respects the symmetric property of equality (ie: if a=b then b=a). There is, however, much debate over which order you should use for style purposes. At the end of the day, stick with the order that makes sense to you and make it consistent through your queries.

Here is a reddit article you can read on the subject or this one from Stackoverflow

1 Like

thank you for the great answer!