Difference b/w putting condition in JOIN clause versus WHERE clause
Posted
by user244953
on Stack Overflow
See other posts from Stack Overflow
or by user244953
Published on 2010-05-08T01:56:44Z
Indexed on
2010/05/08
2:08 UTC
Read the original article
Hit count: 431
sql
|inner-join
Suppose I have 3 tables.
Sales Rep
- Rep Code
- First Name
- Last Name
- Phone
- Sales Team
Orders
- Order Number
- Rep Code
- Customer Number
- Order Date
- Order Status
Customer
- Customer Number
- Name
- Address
- Phone Number
I want to get a detailed report of Sales for 2010. I would be doing a join. I am interested in knowing which of the following 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
© Stack Overflow or respective owner