ShawnGray
asked on
Visual Studio SQL Join
Having trouble with a 1 to many join in a sql query.
Seems its only returning PortfolioCodes when it finds a TradeDate.
How can I get all PortfolioCodes to show even if it doesn't have a TradeDate?
SELECT AdvApp.vPortfolio.Portfoli oCode, AdvApp.vPortfolioTransacti on.TradeDa te
FROM AdvApp.vPortfolio LEFT OUTER JOIN
AdvApp.vPortfolioTransacti on ON AdvApp.vPortfolio.Portfoli oID = AdvApp.vPortfolioTransacti on.Portfol ioID
WHERE (AdvApp.vPortfolioTransact ion.TradeD ate = '9/25/13')
Seems its only returning PortfolioCodes when it finds a TradeDate.
How can I get all PortfolioCodes to show even if it doesn't have a TradeDate?
SELECT AdvApp.vPortfolio.Portfoli
FROM AdvApp.vPortfolio LEFT OUTER JOIN
AdvApp.vPortfolioTransacti
WHERE (AdvApp.vPortfolioTransact
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
As TempDBA has alluded to (no points please), by adding that condition you have essentially converted the query to an implicit INNER JOIN.
Also, you need to get used to using aliases, it makes it easier to read for you and everyone else. As in:
Also, you need to get used to using aliases, it makes it easier to read for you and everyone else. As in:
SELECT p.PortfolioCode,
t.TradeDate
FROM AdvApp.vPortfolio p
LEFT OUTER JOIN AdvApp.vPortfolioTransaction t ON p.PortfolioID = t.PortfolioID
AND t.TradeDate = '20130925'
ASKER
Thank you
Open in new window