cooldude832 Posted August 28, 2008 Share Posted August 28, 2008 I have a query that looks like SELECT customer_data.FileID as FileID, customer_data.FileNum as FileNum, customer_data.UserID as UserID, customer_data.FirstName_1 as FirstName_1, customer_data.LastName_1 as LastName_1, customer_data.SSN_1 as SSN_1, customer_data.DOB_1 as DOB_1, customer_data.Dependants_1 as Dependants_1, customer_data.Phone1_1 as Phone1_1, customer_data.Phone2_1 as Phone2_1, customer_data.Address_1 as Address_1, customer_data.City_1 as City_1, customer_data.State_1 as State_1, customer_data.Zip_1 as Zip_1, customer_data.Email1_1 as Email1_1, customer_data.Email2_1 as Email2_1, customer_data.FirstName_2 as FirstName_2, customer_data.LastName_2 as LastName_2, customer_data.SSN_2 as SSN_2, customer_data.DOB_2 as DOB_2, customer_data.Dependants_2 as Dependants_2, customer_data.Phone1_2 as Phone1_2, customer_data.Phone2_2 as Phone2_2, customer_data.Address_2 as Address_2, customer_data.City_2 as City_2, customer_data.State_2 as State_2, customer_data.Zip_2 as Zip_2, customer_data.Email1_2 as Email1_2, customer_data.Email2_2 as Email2_2, customer_data.EmployeName1_1 as EmployeName1_1, customer_data.EmployeDate1_1 as EmployeDate1_1, customer_data.PayMonth1_1 as PayMonth1_1, customer_data.PayYear1_1 as PayYear1_1, customer_data.Pay20081_1 as Pay20081_1, customer_data.Pay20071_1 as Pay20071_1, customer_data.Pay20061_1 as Pay20061_1, customer_data.EmployeName1_2 as EmployeName1_2, customer_data.EmployeDate1_2 as EmployeDate1_2, customer_data.PayMonth1_2 as PayMonth1_2, customer_data.PayYear1_2 as PayYear1_2, customer_data.Pay20081_2 as Pay20081_2, customer_data.Pay20071_2 as Pay20071_2, customer_data.Pay20061_2 as Pay20061_2, customer_data.EmployeName2_1 as EmployeName2_1, customer_data.EmployeDate2_1 as EmployeDate2_1, customer_data.PayMonth2_1 as PayMonth2_1, customer_data.PayYear2_1 as PayYear2_1, customer_data.Pay20082_1 as Pay20082_1, customer_data.Pay20072_1 as Pay20072_1, customer_data.Pay20062_1 as Pay20062_1, customer_data.EmployeName2_2 as EmployeName2_2, customer_data.EmployeDate2_2 as EmployeDate2_2, customer_data.PayMonth2_2 as PayMonth2_2, customer_data.PayYear2_2 as PayYear2_2, customer_data.Pay20082_2 as Pay20082_2, customer_data.Pay20072_2 as Pay20072_2, customer_data.Pay20062_2 as Pay20062_2, UW.ContactEmail as UW_Email, UW.Phone as UW_Phone, UW.Name as UW_Name, GROUP_CONCAT(DISTINCT customer_lenders.LoanNum ORDER BY LendingID) as LoanNum, GROUP_CONCAT(DISTINCT customer_lenders.LenderName ORDER BY LendingID) as LenderName, GROUP_CONCAT(DISTINCT customer_lenders.Phone ORDER BY LendingID) as LenderPhone, GROUP_CONCAT(DISTINCT customer_lenders.Rate ORDER BY LendingID) as LenderRate, GROUP_CONCAT(DISTINCT customer_lenders.Payment ORDER BY LendingID) as LenderPayment, GROUP_CONCAT(DISTINCT customer_lenders.Status ORDER BY LendingID) as LenderStatus, GROUP_CONCAT(DISTINCT customer_lenders.Program ORDER BY LendingID) as LenderProgram, GROUP_CONCAT(DISTINCT customer_lenders.DateOpened ORDER BY LendingID) as LenderDateOpened, GROUP_CONCAT(DISTINCT customer_liabilities.AccountNumber ORDER BY LiabilityID) as LibAccountNumber, GROUP_CONCAT(DISTINCT customer_liabilities.Name ORDER BY LiabilityID) as LibName, GROUP_CONCAT(DISTINCT customer_liabilities.Balance ORDER BY LiabilityID) as LibBalance, GROUP_CONCAT(DISTINCT customer_liabilities.MonthlyAmount ORDER BY LiabilityID) as LibMonthly, GROUP_CONCAT(DISTINCT customer_logs.Date_Entered ORDER BY LogID) as LogDate, GROUP_CONCAT(DISTINCT customer_logs.Message ORDER BY LogID) as LogMessage FROM `customer_data` LEFT JOIN `users` ON(users.UserID = customer_data.UserID) LEFT JOIN `users` as UW ON (UW.UserID = users.UnderwriterID) LEFT JOIN `customer_lenders` ON(customer_lenders.UserID = customer_data.UserID) LEFT JOIN `customer_liabilities` ON(customer_liabilities.UserID = customer_data.UserID) LEFT JOIN `customer_logs` ON (customer_logs.UserID = customer_data.UserID) WHERE customer_data.UserID = '19' If the table `customer_liabilities` has no matching rows for the join's ON clause the query returns a NULL value on all fields. However if there is at least 1 row in there it works perfectly fine and returns as expected. No other tables have this null/not null issue any ideas? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted August 28, 2008 Author Share Posted August 28, 2008 apparently changing the JOIN's ON clause so the primary table is first did the trick Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.