Differences b / w that condition JOIN clause versus WHERE clause

Suppose I have 3 tables.

Sales Representative

  • Rep Code
  • Name
  • Surname
  • Phone
  • Email
  • Sales department

Orders

  • Order number
  • Rep Code
  • Client's number
  • order date
  • Order status

Customer

  • Client's number
  • Name
  • The address
  • Phone number

I want to receive a detailed sales report for 2010. I would join. I am interested to know which of the following functions is more efficient and why?

SELECT 
    O.OrderNum, R.Name, C.Name
FROM
    Order O INNER JOIN Rep R ON O.RepCode = R.RepCode
            INNER JOIN Customer C ON O.CustomerNumber = C.CustomerNumber
WHERE
    O.OrderDate >= '01/01/2010'

OR

SELECT 
    O.OrderNum, R.Name, C.Name
FROM
    Order O INNER JOIN Rep R ON (O.RepCode = R.RepCode AND O.OrderDate >= '01/01/2010')
            INNER JOIN Customer C ON O.CustomerNumber = C.CustomerNumber
+3
source share
1 answer

EVENTS should reflect the relationship aspect of your tables. The WHERE clause is where you filter records. I prefer the first one.

Make it readable first, relationships between tables should be obvious (using JOIN), then profile

, , ,

- , ; , where . , Postgres MySQL EXPLAIN SELECT ..., SQL Server Ctrl + K, SQL Server ,

+4

Source: https://habr.com/ru/post/1744580/


All Articles