Is it a Good Practice to Add two Conditions when using a JOIN keyword?

Posted by Raúl Roa on Stack Overflow See other posts from Stack Overflow or by Raúl Roa
Published on 2010-03-12T21:16:24Z Indexed on 2010/03/12 21:27 UTC
Read the original article Hit count: 241

Filed under:
|
|

I'd like to know if having to conditionals when using a JOIN keyword is a good practice.

I'm trying to filter this resultset by date but I'm unable to get all the branches listed even if there's no expense or income for a date using a WHERE clause. Is there a better way of doing this, if so how?

SELECT
  Branches.Name
  ,SUM(Expenses.Amount) AS Expenses
  ,SUM(Incomes.Amount) AS Incomes
FROM
  Branches
  LEFT JOIN Expenses
    ON Branches.Id = Expenses.BranchId AND Expenses.Date = '3/11/2010'
  LEFT JOIN Incomes
    ON Branches.Id = Incomes.BranchId AND Incomes.Date = '3/11/2010'
GROUP BY Branches.Name

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql