Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Jun 2016
    Posts
    47
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Why isn't this LEFT JOIN working properly

    This LEFT JOIN should be showing all values in the EPF table, regardless whether they are in the CSBPOS table, and yet it shows only the values that are in both the EPF and CSBPOS Tables, like an inner join would. What am I missing?

    Code:
    $stmt = $db->prepare("
    SELECT *, t1._A _A1, t2._A _A2, t1._B _B1, t2._B _B2, t1._I _I1, t2._I _I2
    FROM EPF
    	LEFT JOIN MorningstarZSplitCleaned1 t1
    		ON EPF.FundTicker = t1._A
    	INNER JOIN MorningstarZSplitCleaned1 t2
    		ON t1._AI = t2._AI
    	LEFT JOIN CSBPOS
    	    ON EPF.FundTicker = CSBPOS.Symbol
    	INNER JOIN SchwabAvailability
    	    ON t2._A = SDAQ_Symbol
    WHERE EPF.PlanCode = :userinputcode AND t1._FH != 1 AND t2._FH = 1 AND CSBPOS.Code = :userinputcode
    ORDER by _A1, _A2
    	");
    Same with this table:

    Code:
    $stmt2 = $db->prepare("
    SELECT *
    FROM EPF
    	INNER JOIN MorningstarZSplitCleaned1 t1
    		ON EPF.FundTicker = t1._A
        INNER JOIN MorningstarZSplitCleaned2 t2
    		ON EPF.FundTicker = t2.A_z
        LEFT JOIN CSBPOS CSPO
    	    ON EPF.FundTicker = CSPO.Symbol
    WHERE EPF.PlanCode = :userinputcode AND CSPO.Code = :userinputcode
    ORDER by t1._A
    	");

    edit: I just realized it's probably from this line in the WHERE clause: AND CSBPOS.Code = :userinputcode

    But when I take that out... it doesn't work.

    Edit: I'm sorry, I always figure it out after posting on here.
    Last edited by HalPlz; Dec 6th, 2018 at 06:30 AM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •