I am using SQL Server 2008.
Whats is the difference between :
With conditions in the Where clause
select customer.Id,
order.Id
from Customer customer
left outer join Order order on order.customerId = customer.Id
where
order.deleted =0
With conditions on the ON clause
select customer.Id,
order.Id
from Customer customer
left outer join Order order
on order.customerId = customer.Id
and order.deleted =0
And how do the two compare with
select customer.Id,
order.Id
from Customer customer
inner join Order order on order.customerId = customer.Id
where
order.deleted =0
I think you should learn about
sql joins. Here is a nice link to start.Basically,
Case 1: You are filtering
order.deleted =0which could benullas itis the
right table of a left join.If right table does not have a mapping row, columns from that table will be null. It should be asISNULL(order.deleted,0)=0Ororder.delete IS NULL or order.delete=0Case 2:
ONis the condition where the two tables are joining andcondition
order.deleted =0is checked (I think) before the joinCase 3: Simple
JOIN or INNER JOINwhere exact rows are mapped from both sides